Login and Re-Direct

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
cupaball
Forum Commoner
Posts: 85
Joined: Sun Feb 12, 2006 1:46 pm

Login and Re-Direct

Post by cupaball »

Okay I would like to have a MySql database the holds client into like, username, pw, company, and url direct. (Which I have already done)

I would like to have client login which when the client enters there correct information, it takes them to their page. I have the login down, I just can't figure out how to make it redirect. By the way, I used Dreamweaver to create the login. (don't hold that against me)

Let me know your thoughts.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

$result = mysql_query(' .... ') or die(mysql_error()); // fetch user info, aswell as check against username and password

if (mysql_num_rows($result) > 0) //user was found
{
   $row = mysql_fetch_assoc($result);

   header('Location: http://domain.com/profile.php?id='. $row['id']);
   exit();
}
As you can see, header() is used to redirect the user. However, you must make sure there has been no output sent if you are sending a header, or you'll run into the dreaded Output already sent error.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you can use headers_sent() to judge how you should output the redirection, potentially.
cupaball
Forum Commoner
Posts: 85
Joined: Sun Feb 12, 2006 1:46 pm

Post by cupaball »

thanks, I will give this a try tomorrow.
Post Reply