All the tutorials say to put session start. They don't say if that should be in all pages on the website, or some, or only 1.
所有的教程都说要启动会话。他们没有说这应该出现在网站的所有页面上,或者一些,或者只有一个。
And if it's only 1 page, does it have to be the main page? Or a page with a form that I am making that puts the session ID in the database? If the visitor never visits a page with a session id but they are on the site, do they still have a session id?
如果只有一页,它一定是主页吗?或者我正在做的一个页面,它将会话ID放在数据库中?如果访问者从来没有访问具有会话id的页面,但是他们在站点上,他们仍然有会话id吗?
4 个解决方案
#1
17
You need to put this in each page that need to access the session data before accessing (or creating) any session data.
您需要在访问(或创建)任何会话数据之前访问会话数据的每个页面中都包含此内容。
See: http://php.net/manual/en/function.session-start.php
参见:http://php.net/manual/en/function.session-start.php
#2
15
Just for a matter of completeness you can choose to write session_start();
in all pages, in just one or in none of them. Let me explain this.
为了完整起见,您可以选择编写session_start();在所有的页面中,只有一个或没有一个页面。让我解释这一点。
You need to start session in every script where you need access to $_SESSION
variable but instead of putting session_start();
in every single script you can create a file headers.php and put there all your repetitive code including session_start();
您需要在每个需要访问$_SESSION变量的脚本中启动会话,而不是放置session_start();在每个脚本中都可以创建一个文件头。把所有重复的代码放在那里,包括session_start();
If everything in your application needs access to $_SESSION
you can forget the use of session_start();
simply setting session.auto_start = 1
in your php.ini file. You will be able to access $_SESSION
without writing session_start();
before.
如果应用程序中的所有内容都需要访问$_SESSION,您可以忘记使用session_start();简单地设置会话。在php中,auto_start = 1。ini文件。您将能够访问$_SESSION而无需编写session_start();之前。
更多的在这里
#3
0
Anything that is going to access Session variables needs to start the session.
任何访问会话变量的东西都需要启动会话。
So unless you have a php page that is non-dependent on the session than every page needs it.
除非你有一个php页面不依赖于会话,而不是每个页面都需要它。
#4
0
You need to declare session_start(); in every page if you want to get data from $_SESSION or store data into $_SESSION in those particular page. If you do not need to interact with $_SESSION then you don't have to declare session_start().@hmwhat
您需要声明session_start();如果您想从$_SESSION获取数据或将数据存储到这些特定页面的$_SESSION中,请在每个页面中。如果不需要与$_SESSION交互,则不需要声明session_start().@hmwhat
#1
17
You need to put this in each page that need to access the session data before accessing (or creating) any session data.
您需要在访问(或创建)任何会话数据之前访问会话数据的每个页面中都包含此内容。
See: http://php.net/manual/en/function.session-start.php
参见:http://php.net/manual/en/function.session-start.php
#2
15
Just for a matter of completeness you can choose to write session_start();
in all pages, in just one or in none of them. Let me explain this.
为了完整起见,您可以选择编写session_start();在所有的页面中,只有一个或没有一个页面。让我解释这一点。
You need to start session in every script where you need access to $_SESSION
variable but instead of putting session_start();
in every single script you can create a file headers.php and put there all your repetitive code including session_start();
您需要在每个需要访问$_SESSION变量的脚本中启动会话,而不是放置session_start();在每个脚本中都可以创建一个文件头。把所有重复的代码放在那里,包括session_start();
If everything in your application needs access to $_SESSION
you can forget the use of session_start();
simply setting session.auto_start = 1
in your php.ini file. You will be able to access $_SESSION
without writing session_start();
before.
如果应用程序中的所有内容都需要访问$_SESSION,您可以忘记使用session_start();简单地设置会话。在php中,auto_start = 1。ini文件。您将能够访问$_SESSION而无需编写session_start();之前。
更多的在这里
#3
0
Anything that is going to access Session variables needs to start the session.
任何访问会话变量的东西都需要启动会话。
So unless you have a php page that is non-dependent on the session than every page needs it.
除非你有一个php页面不依赖于会话,而不是每个页面都需要它。
#4
0
You need to declare session_start(); in every page if you want to get data from $_SESSION or store data into $_SESSION in those particular page. If you do not need to interact with $_SESSION then you don't have to declare session_start().@hmwhat
您需要声明session_start();如果您想从$_SESSION获取数据或将数据存储到这些特定页面的$_SESSION中,请在每个页面中。如果不需要与$_SESSION交互,则不需要声明session_start().@hmwhat