2011-02-26 184 views
0

我在config.php文件中使用session_start()函数,并且此文件包含在所有文件中。在我的add_page.php页面中,我提交表单并在会话中保存一条消息(在提交操作中),然后重定向到index.php页面(使用头('location:...'))。但在重新导演之后,我没有收到会话中的消息。其他会话数据存在像用户名,logged_in等任何想法?PHP会话问题

代码波纹管(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>&nbsp;</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> 

+1

如何显示一些代码? – 2011-02-26 17:37:40

+0

请显示一些代码关于问题 – kjy112 2011-02-26 17:38:15

+0

是的,需要看到一些代码来解决这个问题。 – mcbeav 2011-02-26 17:38:35

回答

2

确保调用发生session_start()之前任何呼叫会话中所保存的消息。必须在需要会话的每个页面请求上调用session_start(),并且必须在页面的最开始发生,即使在发生提交操作之前也是如此。

编辑

http://bugs.php.net/bug.php?id=14636以获取更多信息,并提出了一些建议尝试。