I have a login system on a website it works ok but there is one thing I need to add to the php and I do not know how to so could really do with some help.
After login the user is sent to myaccount.php. This is where I need the help.
All together I will have 4 users, each have there own seperate html page which I need them only to have access to. I don't know how to do this.
I somehow need to have a link on the myaccount.php page that they and only they can click to take them to their own page.
At the moment each user gets a welcome user message when they log in and that seems to work ok for the different users.
I will post the code to the login.php and myaccount.php below.
Can someone please take a look and see what I have to add to enable user1 to go to user1.html and user2 to go to user2.html and so on.
Many thanks in advance:
PHP Code:
<?php
include 'dbc.php';
$err = array();
foreach($_GET as $key => $value) { $get[$key] = filter($value); //get variables are filtered. }
if ($_POST['doLogin']=='Login') {
foreach($_POST as $key => $value) { $data[$key] = filter($value); // post variables are filtered }
$user_email = $data['usr_email']; $pass = $data['pwd'];
if (strpos($user_email,'@') === false) { $user_cond = "user_name='$user_email'"; } else { $user_cond = "user_email='$user_email'"; }
$result = mysql_query("SELECT `id`,`pwd`,`full_name`,`approved`,`user_level` FROM users WHERE $user_cond AND `banned` = '0' ") or die (mysql_error()); $num = mysql_num_rows($result);
// Match row found with more than 1 results - the user is authenticated. if ( $num > 0 ) { list($id,$pwd,$full_name,$approved,$user_level) = mysql_fetch_row($result); if(!$approved) { //$msg = urlencode("Account not activated. Please check your email for activation code"); $err[] = "Account not activated. Please check your email for activation code"; //header("Location: login.php?msg=$msg"); //exit(); } //check against salt if ($pwd === PwdHash($pass,substr($pwd,0,9))) { if(empty($err)){
// this sets session and logs user in session_start(); session_regenerate_id (true); //prevent against session fixation attacks.
// this sets variables in the session $_SESSION['user_id']= $id; $_SESSION['user_name'] = $full_name; $_SESSION['user_level'] = $user_level; $_SESSION['HTTP_USER_AGENT'] = md5($_SERVER['HTTP_USER_AGENT']); //update the timestamp and key for cookie $stamp = time(); $ckey = GenKey(); mysql_query("update users set `ctime`='$stamp', `ckey` = '$ckey' where id='$id'") or die(mysql_error()); //set a cookie if(isset($_POST['remember'])){ setcookie("user_id", $_SESSION['user_id'], time()+60*60*24*COOKIE_TIME_OUT, "/"); setcookie("user_key", sha1($ckey), time()+60*60*24*COOKIE_TIME_OUT, "/"); setcookie("user_name",$_SESSION['user_name'], time()+60*60*24*COOKIE_TIME_OUT, "/"); } header("Location: myaccount.php"); } } else { //$msg = urlencode("Invalid Login. Please try again with correct user email and password. "); $err[] = "Invalid Login. Please try again with correct user email and password."; //header("Location: login.php?msg=$msg"); } } else { $err[] = "Error - Invalid login. No such user exists"; } }
?>
And myaccount.php <?php include 'dbc.php'; page_protect();
?> <?php /*********************** MYACCOUNT MENU **************************** This code shows my account menu only to logged in users. Copy this code till END and place it in a new html or php where you want to show myaccount options. This is only visible to logged in users *******************************************************************/ if (isset($_SESSION['user_id'])) {?> <div class="myaccount"> <p><strong>My Account</strong></p> <a href="myaccount.php">My Account</a><br> <a href="mysettings.php">Settings</a><br> <a href="logout.php">Logout</a></div> <?php } if (checkAdmin()) { /*******************************END**************************/ ?> <p> <a href="admin.php">Admin CP </a></p> <?php } ?> <p> </p> <p> </p> <p> </p></td> <td width="732" valign="top"><p> </p> <h3 class="titlehdr">Welcome <?php echo $_SESSION['user_name'];?></h3> <?php if (isset($_GET['msg'])) { echo "<div class=\"error\">$_GET[msg]</div>"; } ?>
Last edited by chrishirst; 09-14-2010 at 05:04 PM..
|