简体   繁体   English

页面之间的会话数据丢失PHP?

[英]Session data lost between pages PHP?

I am making a news add form using post method. 我正在使用post方法制作新闻添加表单。 In the second page i make data validation. 在第二页中,我进行数据验证。 I define the variables like $message = $_POST["message"] and after that $_SESSION['message'] = "$message"; 我定义了像$message = $_POST["message"]这样的变量,然后$_SESSION['message'] = "$message"; after that I echo the session var and everything look fine the data appear. 之后,我回显了会话var,一切看起来都很好,数据出现了。 And when I click to send which go to another page to add the data to the DB the session vars a empty. 当我单击发送将其转到另一个页面以将数据添加到数据库时,会话变量为空。 There is session_start on every page if i define veriable like $_SESSION="test" it passess all 3 pages but the data generated in the form is lost. 如果我像$_SESSION="test"一样定义veriable,则每个页面上都有session_start,它将通过所有3个页面,但是以表格形式生成的数据将丢失。 Please help! 请帮忙!

$_SESSION="test" is overwriting all of your session data. $_SESSION="test"将覆盖您的所有会话数据。

Instead you should do what you are doing in other places and use $_SESSION['test']="test" . 相反,您应该在其他地方执行操作,并使用$_SESSION['test']="test"

This will put a new item into your $_SESSION array instead of overwriting all session variables. 这会将新项目放入$_SESSION数组,而不是覆盖所有会话变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM