login and redirect to user page

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
brentc73
Forum Newbie
Posts: 4
Joined: Fri May 05, 2006 12:00 pm

login and redirect to user page

Post 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
thiscatis
Forum Contributor
Posts: 434
Joined: Thu Jul 20, 2006 11:00 am

Post 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..
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
brentc73
Forum Newbie
Posts: 4
Joined: Fri May 05, 2006 12:00 pm

Post by brentc73 »

Thank you
Post Reply