Page 1 of 1

login and redirect to user page

Posted: Wed Jul 26, 2006 6:43 pm
by brentc73
I am a newbie and need help. I have a login script that logs a user into the members pager. What I want it to have the user be directed to his member page and not a general members page.

Basically when user Susie logs in I want her to go to susie.php page
when Tom logs in I want him to go to tom.php.

Below is the login script ... any help would be very much appreciated

-----------------------------------------------------------------------------------

login.php

Code: Select all

<?php
$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password="password"; // Mysql password 
$db_name="dbname"; // Database name 
$tbl_name="tablename"; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

session_start();
$username = $_POST['username'];
$password = $_POST['password'];
$query = "select * from users where username='$username' and password='$password'";
$result = mysql_query($query);
if (mysql_num_rows($result) != 1) {
$error = "Bad Login";
include "login.php";
} else {
// set a cookie 	 
$_SESSION['username']=$username;
header("Location: members.php"); 
exit; 
} 
?>
Thanks

Posted: Wed Jul 26, 2006 6:54 pm
by thiscatis
are tom.php & susie.php actual files?
instead I think it would be better to use
the link members.php?user=USERNAME
With your code you can easily get the username from the loginscript and redirect it to that page
and then just add a check that only that user can login to that particular memberpage..

Posted: Wed Jul 26, 2006 6:57 pm
by RobertGonzalez
And you can use mod_rewrite to simulate their page names, so that members.php?username=tom gets rewritten as /members/tom.php.

Posted: Wed Jul 26, 2006 8:20 pm
by brentc73
Thank you