Heim  >  Artikel  >  Backend-Entwicklung  >  session_start()如何使用?

session_start()如何使用?

WBOY
WBOYOriginal
2016-06-23 14:26:35979Durchsuche

本帖最后由 xwmr1988 于 2013-11-05 16:07:59 编辑

php.ini中session.auto_start=0
页面一index.php:
<?php session_start();?><?php	if(isset($_POST['submit'])){		$_SESSION['season']=$_POST['season'];		header('Location:test.php');	}?><b>存储会话</b><hr />选择需要设置的数据:<form id="form1" name="form1" action="index.php" method="post"><select name="season" id="season">	<option value="空">  </option>	<option value="春天">春天</option>	<option value="夏天">夏天</option>    <option value="秋天">秋天</option>    <option value="冬天">冬天</option></select><br /><br /><input type="submit" name="submit" id="submit" value="提交" /></form>

页面二test.php:
<?php	session_start();?><?php	$season=$_SESSION['season'];	echo '<b>读取会话<b/><hr />';	switch($season){		case '春天':			echo '现在是绿意盎然的 春天';			break;		case '夏天':			echo '现在是热情四溢的 夏天';			break;		case '秋天':			echo '现在是硕果累累的 秋天';			break;		case '冬天':			echo '现在是白雪皑皑的 冬天';			break;		default:			echo '对不起,会话中没有数据,或者不存在该会话。';	}?> 

运行页面一:

提交到页面二:

为什么会出现这种警告?怎么解决?除了设置session.auto_start=1

回复讨论(解决方案)

确认test.php 没有bom头

确认test.php 没有bom头
的确是这个原因,多谢大虾,终于解决了这个让人头疼的问题。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn