Alright having a small issue with sessions. It seems that some browsers the sessions arent being placed, like my dad's mac book, but the thing is his Safari is only blocking cookies from third parties, even when i stated never block the session also wasnt started. Its only like this on a small number of examples; my brothers mac works fine. Anyway here is the code:
好的,有一个小问题。似乎有些浏览器会像我爸爸的mac book一样被放置,但是他的Safari只是阻止来自第三方的cookie,即使我声明从不阻止会话也没有启动。它只在少数几个例子中是这样的;我的兄弟mac工作得很好。这里是代码:
Login Page:
登录页面:
if ($email==$dbusername&&md5($pass)==$dbpassword){
$_SESSION['username']=$email;
header( 'Location: http://www.website/start.php' ) ;
Start Page:
开始页面:
session_start();
if($_SESSION['username']){
}
else{
die("<li style=\" color: black; font-family: Helvetica, sans-serif;
margin-left: 550px; margin-top: 300px; font-size: 24px; \" ><a style=\"text-decoration: none;\" href=\"index.php\">Login or Register<a></li> ");
anyway on my dads mac, and another pc i tested today i found that the session was never created. Any help? Also im new to *, please dont bash me for this post, i mean from everything i have heard about *, mainly it being useful for people like me, why would bashing even be allowed, if i am posting in the wrong section kindly tell me so and redirect me. Its professionlism. Thanks guys.
不管怎么说,在我的父亲麦克和我今天测试的另一台个人电脑上,我发现这个会话从来没有被创造出来。任何帮助吗?我对*也很陌生,请不要因为这篇文章而抨击我,我的意思是我听到的关于*的所有事情,主要是它对像我这样的人有用,为什么还要被允许,如果我在错误的地方张贴,请告诉我,然后重定向我。其professionlism。谢谢你的家伙。
2 个解决方案
#1
0
Although you need to answer @haynar1658's question, if you are using session_start()
on both pages, a potential problem could be your redirect:
虽然您需要回答@haynar1658的问题,但是如果您在两页上使用session_start(),那么可能会出现一个问题:
header( 'Location: http://www.website/start.php' ) ;
(I am assuming that your mean www.website.com
or something similar).
(我假设你的意思是www.website.com或类似的东西)。
If your site is both available as www.website.com
and website.com
, the problem you describe would occur if you login on website.com
. Then you will have a session open on website.com
but not on www.website.com
so after your redirect you will see your error message.
如果你的网站都是www.website.com和website.com,那么你所描述的问题将会出现在你登陆website.com的时候。然后你会在website.com上开一个session,但不是在www.website.com上,所以在你重定向之后,你会看到你的错误信息。
Edit: To have your session work across sub-domains, you can use something like:
编辑:让您的会话工作跨越子域,您可以使用以下方法:
$some_name = session_name("some_name");
session_set_cookie_params(0, '/', '.website.com');
session_start();
everywhere where you use session_start();
.
在任何地方使用session_start();
An alternative would be to use something like an .htaccess
file to always redirect to the www
version.
另一种选择是使用像.htaccess文件这样的东西,以始终重定向到www版本。
#2
0
session_start()
should be on the page that saves to the session as well as on the page that retrieves data from the session.
session_start()应该在保存到会话的页面上,以及从会话中检索数据的页面上。
I usually have session_start()
at the top of a file that's included on all pages.
我通常在包含在所有页面的文件的顶部有session_start()。
#1
0
Although you need to answer @haynar1658's question, if you are using session_start()
on both pages, a potential problem could be your redirect:
虽然您需要回答@haynar1658的问题,但是如果您在两页上使用session_start(),那么可能会出现一个问题:
header( 'Location: http://www.website/start.php' ) ;
(I am assuming that your mean www.website.com
or something similar).
(我假设你的意思是www.website.com或类似的东西)。
If your site is both available as www.website.com
and website.com
, the problem you describe would occur if you login on website.com
. Then you will have a session open on website.com
but not on www.website.com
so after your redirect you will see your error message.
如果你的网站都是www.website.com和website.com,那么你所描述的问题将会出现在你登陆website.com的时候。然后你会在website.com上开一个session,但不是在www.website.com上,所以在你重定向之后,你会看到你的错误信息。
Edit: To have your session work across sub-domains, you can use something like:
编辑:让您的会话工作跨越子域,您可以使用以下方法:
$some_name = session_name("some_name");
session_set_cookie_params(0, '/', '.website.com');
session_start();
everywhere where you use session_start();
.
在任何地方使用session_start();
An alternative would be to use something like an .htaccess
file to always redirect to the www
version.
另一种选择是使用像.htaccess文件这样的东西,以始终重定向到www版本。
#2
0
session_start()
should be on the page that saves to the session as well as on the page that retrieves data from the session.
session_start()应该在保存到会话的页面上,以及从会话中检索数据的页面上。
I usually have session_start()
at the top of a file that's included on all pages.
我通常在包含在所有页面的文件的顶部有session_start()。