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> PHP: _______________________________________________ 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 PHP: anyone got any ideas where i am going wrong here? thanks sophia
Hey Dr. Nick! Replace header("Location: /users/{$username}.php"); die; Code (markup): with header("Location: users/{$username}.php"); exit; Code (markup): Also, replace the "die" on the user1.php page with "exit" It's never a good idea to use "die" unless you've encountered a fatal system error.
hi sea otter thanks for your response but alass, still no joy this is quite advanced stuff for me by the way so your help is greatly appreciated sophia
No problem ok, a couple more minor things in user1.php. It's easier for me to post a new file here: <?php session_start(); $page = explode('.', basename(htmlentities($_SERVER['PHP_SELF']))); if (empty($_SESSION['user']) or ($page['0'] !== $_SESSION['user'])) { header('Location: ../login.php'); die; } echo 'Welcome...'; ?> PHP:
still the same ok, now i think i am getting somewhere the submit button is in fact now opening a page, but it is the main index.html of the site? mysite.com/index.html login: mysite.com/login/login.php users: mysite.com/users/user1.php login page <?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> PHP: user page <?php session_start(); $page = basename(htmlentities($_SERVER['PHP_SELF'])); $page = explode(".", $page); if(empty($_SESSION['user']) or ($page['0'] != $_SESSION['user'])){ header("Location: /"); die; } ?> user html PHP:
The problem is your massive 'if' there: because of the lack of extra brackets, you are requiring the password to equal 'pass1' AND 'pass2' AND 'pass3' etc. You need to add some more brackets to group your ands and ors correctly. Try: 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") )){ PHP:
YYYYAAAAAAYYYYYYYYY!!!!!!!!!!! DONE IT!!!!!!!!!!!! gee wizz what a ride ... hehehehehe main site; site.com.index.html login page; site.com/login/login.php users pages site.com/users/user1.php | user2.php................. login page <?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> PHP: change "user1" to "your clients name" ... "user2" "user3" etc change "pass1" to "your clients password" ... "pass2" "pass3" etc user page <?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 goes here PHP: add this to each user page and thats it ... its a wrap multi-client log-in to personal "private" pages within your site ehehehehehe thanks to all sophia