会话不适用于MAMP
When i try to run my site on localhost i get an error:
Undefined index: log in ... on line 137
Within this file there is a line:
if (!$_SESSION['log']) { ...
Everything works on server, but not on localhost. What can I do to fix it?
当我尝试在localhost上运行我的网站时出现错误: p>
未定义的索引:在第137行登录...
code> pre>
在此文件中有一行: p>
if(!$ _ SESSION ['log']){...
code> pre>
一切都在服务器上运行,但不在localhost上运行。 我该怎么做才能解决它? p>
div>
There is probably a difference between the level of error reporting between the server and your local setup.
If you want to check if the variable is set (assuming that a session has been started...), you should use:
if (!isset($_SESSION['log'])) {
Or if you want to check if it is not set and / or empty or false
:
if (empty($_SESSION['log'])) {
Both will not generate any warnings for non-set variables or array indices.
It probably isn't working "on server," but is instead just not showing the error message to the page.
You can fix the warning re: the index by changing your if statement to this:
if (isset($_SESSION['log']) && !$_SESSION['log']) {
Or to whatever condition you need it to be.