简体   繁体   English

站点在localhost上完美运行,但在服务器上运行不正常

[英]Site works perfectly on localhost, but not on server

I have weird situation. 我有奇怪的情况。

I'm using this piece of code to logout the user from the site: 我正在使用这段代码从网站注销用户:

case 'exit':
    setcookie("hash", "", time() - 3600, '/');
    header('Location: /main');
    exit();
    break;

Exactly the same code is used on localhost, only difference is that on the server it won't logout. 在localhost上使用完全相同的代码,唯一的区别是在服务器上它不会注销。 Just goes to the /main page and that's it. 只需转到/main主页即可。 User stays logged in, but it perfectly works on localhost. 用户保持登录状态,但它完全适用于localhost。

I've had this problem aswell, I found out cookies and sessions are required by most webservices to be the VERY first line of the file. 我也遇到过这个问题,我发现大多数web服务都需要cookie和会话才能成为文件的第一行。 Remember that header() must be called before any actual output is sent. 请记住,必须在发送任何实际输出之前调用header()。

More about headers: http://php.net/manual/en/function.header.php 有关标题的更多信息: http//php.net/manual/en/function.header.php

You should give complete route on the server. 您应该在服务器上提供完整的路由。 //example header("Location: http://www.example.com/login "); //示例标题(“位置: http//www.example.com/login ”);

暂无
暂无

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

相关问题 我的Web应用在服务器上看起来与众不同,并且可以在localhost上完美运行 - my web app looks different on server and works perfectly on localhost 敏捷工具包CRUD在本地主机上完美运行,在服务器上引发错误 - Agile Toolkit CRUD works perfectly on localhost throws error on server PHP - file_get_contents() 在 localhost 但在实时服务器上完美运行 - PHP - file_get_contents() works perfectly on localhost but on live server 我的 Codeigniter 网站可以在本地主机上运行,但不能在 web 服务器上运行? 500 内部服务器 - My Codeigniter site works on localhost but not on web server? 500 internal server 错误503:服务不可用,但本地主机运行正常 - Error 503: Service Unavaiable but localhost works perfectly 托管 Laravel 不存储图像但在本地主机上完美运行 - hosted Laravel not storing images but works perfectly on localhost 本地主机数据库完美运行,托管不 - Localhost database works perfectly, hosting doesn't PHP App在localhost上完美运行,在任何Web服务器上完全失败,并出现一些奇怪的错误 - PHP App works perfectly on localhost and fails completely on any web server with some strange errors 填充php数组变量不适用于godaddy服务器(php版本5.3.24)在localhost中完美运行 - populating php array variable is not working in godaddy server(php version 5.3.24) works perfectly in localhost Laravel 8 站点在本地主机上运行良好,但在共享托管服务器上运行良好 - Laravel 8 site works well on localhost but not on shared hosting server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM