PHP:会话已经开始 - 忽略 session_start() 仅在 Windows 中出现
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13759187/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP: A session had already been started - ignoring session_start() comes only in windows
提问by Muthuraj Muthulingam
Possible Duplicate:
PHP sessions that have already been started
可能重复:
已启动的 PHP 会话
I have run a my PHP project on windows and also Mac with same code . But I got this error when I run my project in windows not in Mac.
我在 Windows 和 Mac 上运行了我的 PHP 项目,代码相同。但是当我在 Windows 而非 Mac 中运行我的项目时出现此错误。
error message is .
错误信息是。
A session had already been started - ignoring session_start()
which is come only on Windows system. But In Mac I didnt get any error message. Please any one give me a solution .....
仅在 Windows 系统上出现。但是在 Mac 中我没有收到任何错误消息。请任何人给我一个解决方案......
回答by Peter Kiss
You said that you starts session with a check:
你说你用支票开始会话:
if(!isset($_SESSION)){
session_start();
}
The fact is the $_SESSION always exists and if you aren't put something in it then it will be always empty, so the statment will return always true.
事实是 $_SESSION 总是存在的,如果你没有在里面放东西,那么它总是空的,所以该语句将始终返回 true。
回答by Sridhar
I didnt know why windows shows the error and Mac dont.
But You can try to replace all the session_start()by
我不知道为什么 Windows 显示错误而 Mac 不显示。但是您可以尝试全部替换the session_start()为
if(!isset($_SESSION))
{
session_start();
}
This will may help you..
这可能会帮助你..
回答by Rudi Visser
This message is an E_NOTICE. The reason you're only seeing it on the Windows machine is most likely because you have error_reportingset differently.
此消息是一个E_NOTICE. 您只在 Windows 机器上看到它的原因很可能是因为您的error_reporting设置不同。
If you search php.inifor error_reportingyou should exclude E_NOTICEif you don't want to see it.
如果您搜索php.ini为error_reporting您应该排除E_NOTICE,如果你不希望看到它。
Alternatively, fix your code to not start a session more than once. Ideally, you would only have one core code file that would start your session and no other instances of session_start()(ie. don't put it on each page). You can then include this on each page, or create a routing pattern that will ensure initialisation code is called on each pageload.
或者,修复您的代码以不多次启动会话。理想情况下,您将只有一个核心代码文件来启动您的会话,而没有其他实例session_start()(即不要将其放在每一页上)。然后,您可以将其包含在每个页面上,或者创建一个路由模式,以确保在每个页面加载时调用初始化代码。
回答by Rainer.R
Have a look at session.auto_start in your php.ini (http://php.net/session.auto-start), most likely the session is automatically started
看看你的 php.ini (http://php.net/session.auto-start) 中的 session.auto_start,会话很可能是自动启动的

