Home >Backend Development >PHP Tutorial >session_start()怎么使用

session_start()怎么使用

WBOY
WBOYOriginal
2016-06-13 11:39:321274browse

session_start()如何使用?

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

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

运行页面一:

提交到页面二:

为什么会出现这种警告?怎么解决?除了设置session.auto_start=1
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn