sophia_ Posted September 8, 2007 Share Posted September 8, 2007 hi everyone got a problem accessing/opening the users' page here what is meant to happen; the user logs on with user name and password the submit button then opens the users page ie: username: user1 password : pass1 opens user1.php but it doesn't this is the folder structure: login/users/user1.php login.php sits in the root of the 'login' folder user1.php sits in the sub-folder 'users' here is the code....... _________________________________________ login.php _________________________________________ <?php session_start(); $message = "Please Log in."; if(!empty($_POST['username']) and !empty($_POST['password'])){ $username = $_POST['username']; $password = $_POST['password']; if(($username == "user1") and ($password == "pass1") or ($username == "user2") and ($password == "pass2") or ($username == "user3") and ($password == "pass3") or ($username == "user4") and ($password == "pass4") or ($username == "user5") and ($password == "pass5") or ($username == "user6") and ($password == "pass6") or ($username == "user7") and ($password == "pass7")){ $_SESSION['user'] = $username; header("Location: /users/{$username}.php"); die; }else{ $message = "Your username and or password are incorrect."; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Login</title> </head> <body> <h1><?php echo($message); ?></h1> <form action="<?php echo(basename(htmlentities($_SERVER['PHP_SELF']))); ?>" method="post" accept-charset="utf-8"> <p>Username:<input type="text" name="username" /></p> <p>Password:<input type="password" name="password" /></p> <p><input type="submit" value="Login →" /></p> </form> </body> </html> _______________________________________________ user1.php _______________________________________________ <?php session_start(); $page = basename(htmlentities($_SERVER['PHP_SELF'])); $page = explode(".", $page); if(!empty($_SESSION['user']) or ($page['0'] != $_SESSION['user'])){ header("Location: /"); die; } ?> the users html page content is here anyone got any ideas where i am going wrong here? thanks sophia Link to comment https://forums.phpfreaks.com/topic/68437-problem-with-php-page-not-linking/ Share on other sites More sharing options...
darkfreaks Posted September 8, 2007 Share Posted September 8, 2007 dont put $user in the header? i dont get what your trying to accomplish here Link to comment https://forums.phpfreaks.com/topic/68437-problem-with-php-page-not-linking/#findComment-344091 Share on other sites More sharing options...
sophia_ Posted September 8, 2007 Author Share Posted September 8, 2007 hi darkfreaks thanks for the reply sorry if my post is a little confusing ... i dont really know that much about php what is meant to be happening here is that when a user enters the username and password in the login page, the user then gets redirected to their own private part of the site ie.. username: user1 password:pass1 username: user2 password: pass2 user "user1" logs on and then gets redirected to ../users/user1.php user "user2" logs on and then gets redirected to ../users/user2.php i cant get the blooming thing to work though sophia Link to comment https://forums.phpfreaks.com/topic/68437-problem-with-php-page-not-linking/#findComment-344095 Share on other sites More sharing options...
darkfreaks Posted September 8, 2007 Share Posted September 8, 2007 <?php $_SESSION['user'] = $username; if($username == "user1") || ($password == "pass1") { header("Location: /users/user1.php?user=$username"); } else { if($username)== "user2" || ($password == "pass2") { header("Location: /users/user2.php?user=$username"); }else{ if($username == "user3") || ($password == "pass3") { header("Location: /users/user3.php?user=$username"); }else{ if($username == "user4") || ($password == "pass4") { header("Location: /users/user4.php?user=$username"); }else{ if($username == "user5") || ($password == "pass5") { header("Location: /users/user5.php?user=$username"); }else{ if($username == "user6") || ($password == "pass6") { header("Location: /users/user6.php?user=$username"); }else{ if($username == "user7") || ($password == "pass7") { header("Location: /users/user7.php?user=$username"); }else{ $message = "Your username and or password are incorrect.";} ?> Link to comment https://forums.phpfreaks.com/topic/68437-problem-with-php-page-not-linking/#findComment-344117 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.