PHP 标签前有空格
我用 PHP 编写了一个应用程序。它包括
1:登录表单
2:欢迎页面
3:注销表单重定向到登录表单。
我的 php.ini 中的 register_global =On。
我的应用程序在 LAMP 和 WAMP 上正常运行。但它没有在实时服务器上设置会话。
但是,逐行检查后,在会话设置文件中,在启动''
之前有一个空格。删除该空间后,我的应用程序可以在实时服务器上正常运行。
会话未设置的 ''
之前的空格背后的原因可能是什么?
I have written an application in PHP. It includes
1: login form
2: Welcome page
3: Logout form which is redirected to login form.
My register_global =On in php.ini.
My application has working properly on LAMP and WAMP. But it has not setting session on live server.
But, after checking by line by line, in session setting file, there was single space before starting '<?PHP ...... ?>'
. After removing that space my application has working properly on live server.
What can be the reason behind that space before the ‘<?PHP ...... ?>'
by which session is not setting?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
空格被输出,即发送到浏览器。要打开会话,您需要发送一个所谓的 HTTP 标头,您需要在输出任何内容之前执行此操作。这就是为什么它不起作用。您的错误消息可能是“标头已发送”。
The space is output, i.e. sent to the browser. For opening a session you need to send a so-called HTTP header, which you need to do before anything is output. That's why it didn't work. Your error message probably was "headers already sent".
在发送响应头之前不能发送任何内容;会话在响应标头中发送。由于您事先发送了一个空间,因此您无法开始会话。
从 session_start 的文档中,“要使用基于 cookie 的会话,必须在将任何内容输出到浏览器。”。这包括开头的单个空格。
基本上,任何脚本中的第一件事应该始终是
You can't send any content before sending the response headers; the session is sent in the response headers. Because you sent a space beforehand, you are therefore unable to start a session.
From the documentation on session_start, "To use cookie-based sessions, session_start() must be called before outputing anything to the browser.". This includes the single space at the start.
Basically, the first thing in any script should always be
<?php