Cookie problem.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ecevdoxiadis
Forum Newbie
Posts: 2
Joined: Fri Nov 12, 2004 2:59 am

Cookie problem.

Post by ecevdoxiadis »

I am trying to make a site require username/password and I have achieved that using forms/cookies. I have 2 problems I can't figure out. When cookies are turned off or I go manually to one of the "secure" pages, the browser goes there and I can't prevent it. I have an if statement asking if the cookie is == '' and it recognizes that there is nothing there but it gives me an error saying that the variable ( that I call "cookie" which is the true or false statement that passes from the previous page letting the user log on or not) does not exist. I understand why but I guess my question is how can I make the browser redirect to an other page if there is no cookie there?

Hope I am understandable.
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

it would help if you post your code, but this is a very basic outline of what you need to do


Code: Select all

if (empty($_COOKIE['username'])) {
    header('Location: login.php');
    exit;
} else {
    // check thier credentials and if all ok, allow them in
}

a lot of people still incorrectly do things w/ authentification, id suggest posting the code and letting people help you w/ it.
ecevdoxiadis
Forum Newbie
Posts: 2
Joined: Fri Nov 12, 2004 2:59 am

Thanks

Post by ecevdoxiadis »

Thank you very much. I am relieved to see this working...
Post Reply