我在config.php文件中使用session_start()函数,此文件包含在所有文件中。在我的add_page.php页面中,我在会话中提交表单并保存消息(在提交操作中),然后重定向到index.php页面(使用标题('location:...'))。但在重新指导后,我没有从会话中收到消息。其他会话数据存在像-user,logged_in等任何想法???
代码吼叫(add_news.php)。提交表格后,它会重新定向到news.php。 config.php文件顶部有session_start()函数,它包含在每个页面中:
<?php
include('../include/config.php');
//submit edit data
if (isset($_POST['submit_edit'])) {
$news_head = stripslashes(trim($_POST['news_head']));
$news_details = $_POST['news_details'];
$news_special = ($_POST['news_special']=='')?'0':'1';
$news_status = ($_POST['news_status']=='')?'0':'1';
$data = array('news_head'=>$news_head,
'news_details'=>$news_details,
'news_special'=>$news_special,
'news_status'=>$news_status);
$clause = "news_id = '".$_POST['news_id']."'";
$response = update_data('news', $data, $clause);
if($response)
$_SESSION['success_msg'] = "News updated successfully.";
}
//submit edit data end
?>
<form action="add_news.php" method="post" id="add_news_form">
<input type="hidden" name="news_id" value="<?php echo $news_id ?>" />
<table width="100%" border="0" cellspacing="4" cellpadding="4">
<tr>
<td>News Heading</td>
<td><input type="text" name="news_head" id="news_head" class="required" value="<?php echo $news_head ?>" size="100" /></td>
</tr>
<tr>
<td>News Details</td>
<td><textarea name="news_details" id="news_details" class="editor required" rows="7" cols="60"><?php echo trim(stripslashes($news_details)); ?></textarea></td>
</tr>
<tr>
<td>Special News</td>
<td><input type="checkbox" name="news_special" id="news_special" value="1" <?php if($news_special=='1') echo 'checked="checked"'?> />
[ Checked means special ]</td>
</tr>
<tr>
<td>Status Status</td>
<td><input type="checkbox" name="news_status" id="news_status" value="1" <?php if($news_status=='1') echo 'checked="checked"'?> />
[ Checked means published ]</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Submit" <?php if($_REQUEST['news_id']!="" && $_REQUEST['action']=='edit') echo 'name="submit_edit"'; else echo 'name="submit"'; ?> /></td>
</tr>
</table>
</form>
答案 0 :(得分:2)
确保在任何在会话中保存消息的呼叫之前发生对session_start()
的呼叫。必须在每个需要会话的页面请求上调用session_start()
,并且必须在页面的最开始发生,甚至在提交操作发生之前。
修改强>
有关详细信息和一些建议,请参阅http://bugs.php.net/bug.php?id=14636。