简体   繁体   English

会话不适用于MAMP

[英]Session doesn't work on MAMP

When i try to run my site on localhost i get an error: 当我尝试在localhost上运行我的网站时,出现错误:

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? 我该如何解决?

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 : 或者,如果您要检查它是否未设置和/或为空或为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语句更改为此来修复警告:索引:

if (isset($_SESSION['log']) && !$_SESSION['log']) {

Or to whatever condition you need it to be. 或无论您需要什么条件。

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

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