[英]Where do I end a PHP session so that a variable, created in the first PHP file, can be used in the second file?
I have a website where the user starts on one page and then moves to a second page.我有一个网站,用户从一页开始,然后转到第二页。 The first page initializes and adds values to a counting variable, which I then want to be able to be displayed on the second page.
第一页初始化并将值添加到计数变量,然后我希望能够在第二页上显示该变量。 I know to use a session, but I am wondering how I should properly end the session--do I end it on the first page, or the second page?
我知道使用 session,但我想知道如何正确结束会话——我是在第一页还是第二页结束? Do both pages need to begin with
session_start()
?两个页面都需要以
session_start()
开头吗?
Yes.是的。 Both must use session start.
两者都必须使用 session 启动。 The variable you are talking about is basically termed cookies.
您所说的变量基本上称为cookies。 The variables will be shared throughout the browser sessions.
这些变量将在整个浏览器会话中共享。
To be a little bit more precise, The function session_start();更准确地说,function session_start(); will make the Global
$_SESSION
available for the current active page将使全局
$_SESSION
可用于当前活动页面
So you have to put session_start on each page than require a variable to stay on your session所以你必须把 session_start 放在每个页面上,而不是需要一个变量留在你的 session
You'll also probably want to use session_destroy();您可能还想使用session_destroy(); and session_unset();
和session_unset(); at the last page your users will have to visit
在您的用户必须访问的最后一页
I hope I helped you !我希望我对你有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.