Simple Cookie code
Posted: Sat Jan 03, 2009 12:01 pm
Hai,
Ive only just started learning PHP and i want to make a very simple login.
i know this has almost no security and i should never use it how ever its so i can learn some PHP.
So ive got a login script, once im logged it it says redirecting. During those 5 seconds of redirecting a cookie is created. In the next page and in all the pages i want a code which checks up on that cookie and if it is non existant then you are "logged out" and redirected back to the login page. and even if you try again going on that page you will be put back to the login.
I have all the codes except for the one where it checks for the cookies. I have posted on Yahoo! answers and this is what i got:
http://lite-hosting.net/Login%20code/test.php
(The first page is after the login code so you are being redirected and the cookie is being created so it lasts for 1 hour. This cookie is called TestCookie)
The next page which you are redirected onto has a cookie called "cake" <=== yes very pro i know
so i should be redirected, Right?
well nothing happens
Please help
Thanks a lot and have a happy 2009
Leito
Ive only just started learning PHP and i want to make a very simple login.
i know this has almost no security and i should never use it how ever its so i can learn some PHP.
So ive got a login script, once im logged it it says redirecting. During those 5 seconds of redirecting a cookie is created. In the next page and in all the pages i want a code which checks up on that cookie and if it is non existant then you are "logged out" and redirected back to the login page. and even if you try again going on that page you will be put back to the login.
I have all the codes except for the one where it checks for the cookies. I have posted on Yahoo! answers and this is what i got:
So i have done as this person said and this is what i have done:<?php
if(isset($_COOKIE["Name"]))
{
header("location: somewhere.php");
}
?>
don't forget that all of this comes before the header, so it has to be the first thing sent or it doesn't work. The other alternative would be to buffer your headers, but it's probably just easier to make sure this is stated first.
http://lite-hosting.net/Login%20code/test.php
(The first page is after the login code so you are being redirected and the cookie is being created so it lasts for 1 hour. This cookie is called TestCookie)
The next page which you are redirected onto has a cookie called "cake" <=== yes very pro i know
so i should be redirected, Right?
well nothing happens
Please help
Thanks a lot and have a happy 2009
Leito