[英]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.