Sessions don't work on MAMP

匆匆过客 提交于 2019-12-10 19:24:46

问题


I'm using MAMP, but I have a problem with session. My code works perfectly on WAMP, but doesn't work on MAMP and I don't no why. I looked the phpinfo but there are the same for the session between MAMP and WAMP.

PHP log file : [01-May-2012 12:18:28] PHP Warning: session_start() [<a href='function.session- start'>function.session-start</a>]: Cannot send session cookie - headers already sent by (output started at /Applications/MAMP/htdocs/Website/index.php:7) in /Applications/MAMP/htdocs/Website/header.php on line 2 [01-May-2012 12:18:28] PHP Warning: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at /Applications/MAMP/htdocs/Website/index.php:7) in /Applications/MAMP/htdocs/Website/header.php on line 2

Apache log file : [Tue May 01 12:03:29 2012] [notice] Digest: generating secret for digest authentication ... [Tue May 01 12:03:29 2012] [notice] Digest: done [Tue May 01 12:03:29 2012] [notice] Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8r DAV/2 PHP/5.3.6 configured -- resuming normal operations [Tue May 01 12:04:11 2012] [notice] caught SIGTERM, shutting down [Tue May 01 12:04:24 2012] [notice] Digest: generating secret for digest authentication ... [Tue May 01 12:04:24 2012] [notice] Digest: done [Tue May 01 12:04:24 2012] [notice] Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8r DAV/2 PHP/5.3.6 configured -- resuming normal operations [Tue May 01 12:05:11 2012] [error] [client 127.0.0.1] client denied by server configuration: /Applications/MAMP/htdocs/.DS_Store

Why they doesn't work ?

Thank you.


回答1:


Look here:

 headers already sent by (output started at /Applications/MAMP/htdocs/Website/index.php:7)

in that line there is some output generated before you call session_start(). If you generate ANY output (even just a newline or something, whitespace, you name it) a header gets send and you cannot send another header for session_start().

I doubt it has anything specifically to do with your *AMP.




回答2:


I'm also using MAMP for Mac.

I got the same error message you got.

I solved my problem by:

Instead of having your php on the head of the document. Put the PHP on top before (doctype)

I did this and the code worked.

Also, make sure the (php) tag is the first in the document. Leave no white spaces.

GL



来源:https://stackoverflow.com/questions/10396907/sessions-dont-work-on-mamp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!