login to specific pages based on username

I understand how to build a db-driven login form but I am trying to figure out how to make the login form take you to a page that corresponds to the username you enter. (i.e. Client1 logs in and is redirected to page A. Client2 logs in and is directed to page B).

Do I use If statements and format my table with the usernames and passwords with the desired URLs too?

If($username&&$password) {
echo $URL;
}

I appreciate any help I can get with this.

make a page something like this
[php]
$sql = “SELECT page FROM users WHERE username = '” . $username . “’ AND password = '” . $password . “’;”;
$result = mysql_query($sql);
if(mysql_num_rows == 1) {
$row = mysql_fetch_assoc($result);
echo $row[‘page’];
} else {
echo "incorrect username or password ";
}
[/php]

Hello Mike,

What web app are you trying to create? I don’t think it’s a good idea to create multiple pages for all registered users. What it you have hundreds of users, does that mean you’re to create hundreds of pages?

First of all, you dont want users to manually press urls when logging in, so an idea is as followed:

You add user levels to your database table (example used a lot is members/admins/forumadmins etc).

you let the user login and validate the info entered but before you submit it you check the user level.
[php]
if(isset($_POST[‘login’])) {
if($userlevel == “admin”) {
header('location: www.yourpage.com/admin.php");
} elseif($userlevel == “members”) {
header('location: www.yourpage.com/members.php");
} else {
die(“An error occured”);
}
[/php]

I might have made a script error, but you get the idea.

When you starts string with ’ you must finishes with ', there is the error, you hav started with ’ and finishes with "

header('location: www.yourpage.com/admin.php");

header('location: www.yourpage.com/members.php");

Yes i noticed that as well, but since i cant edit my posts i cant change it. And it was only ment to show the idea, he has to write the code himself anyway.

Sponsor our Newsletter | Privacy Policy | Terms of Service