session_start()如何使用?

WBOY
Release: 2016-06-23 14:26:35
Original
979 people have browsed it

本帖最后由 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>
Copy after login

页面二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 '对不起,会话中没有数据,或者不存在该会话。';	}?> 
Copy after login

运行页面一:

提交到页面二:

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

回复讨论(解决方案)

确认test.php 没有bom头

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!