murdocsvan
Web Programmer
- Messages
- 896
- Location
- Surrey, UK
For some reason im having a great deal of problems with using cookies on my website. I have a login system which i initially set to use sessions, but decided to use cookies as sessions was a bit glitchy. The order of my website goes:
Login form > Check Login Script > Login Success Script > index.htm
on the first script, this is code that sets the cookie:
And this is the piece of code on each page that checks that the cookie is there:
Now for some reason, it will go to the Login Success page, and not have a problem even though that page has the cookie checking code on it. However, when the Login Success page then redirects to the index.htm page, it goes straight back to the login form, thinking the cookie's not there. The second bit of code is identical on all the pages i have protected by the login system.
Thanks in advance.
Login form > Check Login Script > Login Success Script > index.htm
on the first script, this is code that sets the cookie:
PHP:
// Register $myusername, $mypassword and redirect to file "login_success.php"
$expire=time()+60*60*24*5;
setcookie('user', $username, $expire);
header("location:login_success.php");
And this is the piece of code on each page that checks that the cookie is there:
PHP:
<?php
if(!isset($_COOKIE['user']))
{
header("location:login/main_login.htm");
}
?>
Now for some reason, it will go to the Login Success page, and not have a problem even though that page has the cookie checking code on it. However, when the Login Success page then redirects to the index.htm page, it goes straight back to the login form, thinking the cookie's not there. The second bit of code is identical on all the pages i have protected by the login system.
Thanks in advance.