fantasticham Posted November 3, 2009 Share Posted November 3, 2009 I know this is basic stuff but there's a specific way I want to do things that's making this awkward. To begin with, I want to create a login page, just using php with a small list of three users and no way to register. I can do that easily enough, but I want the page to redirect to a specific page for that member once they've logged in. So if I were to login with FantasticHam, it would redirect to website.com/fantasticham/upload.php. Keep in mind I'm trying to keep this as simple as possible and I don't have access to a MySQL database. I am pretty new to PHP, so excuse my ignorance. Quote Link to comment https://forums.phpfreaks.com/topic/180098-login-system-with-redirect-to-specific-user-page/ Share on other sites More sharing options...
JonnoTheDev Posted November 3, 2009 Share Posted November 3, 2009 <?php session_start(); $users['FantasticHam'] = array('password' => 'iop123', 'redirect' => '/fantasticham/upload.php'); $users['JohnDoe'] = array('password' => 'abc123', 'redirect' => '/john/index.php'); if(array_key_exists($_POST['username'],$users)) { if($_POST['password'] == $users[$_POST['username']]['password']) { $_SESSION['loggedIn'] = true; // redirect header('Location:'.$users[$_POST['username']]['redirect']); exit(); } else { // invalid password } } else { // invalid username } ?> <?php // pages that require login if(!$_SESSION['loggedIn']) { header('Location:/login.php'); exit(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/180098-login-system-with-redirect-to-specific-user-page/#findComment-950086 Share on other sites More sharing options...
fantasticham Posted November 3, 2009 Author Share Posted November 3, 2009 Brilliant, thanks for your help. What file to I add this too? The original log in page? Is this alright for the login form? <form method="post" name="frmLogin" id="frmLogin"> <table width="344" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="150">USERNAME:</td> <td width="194"><input name="username" type="text" id="username"></td> </tr> <tr> <td width="150">PASSWORD</td> <td><input name="password" type="password" id="password"></td> </tr> <tr> <td width="150"> </td> <td><input type="submit" name="btnLogin" value="Login"></td> </tr> </table> </form> Sorry for asking really stupid questions, I just need a little more instruction. Quote Link to comment https://forums.phpfreaks.com/topic/180098-login-system-with-redirect-to-specific-user-page/#findComment-950108 Share on other sites More sharing options...
JonnoTheDev Posted November 3, 2009 Share Posted November 3, 2009 yes Quote Link to comment https://forums.phpfreaks.com/topic/180098-login-system-with-redirect-to-specific-user-page/#findComment-950134 Share on other sites More sharing options...
fantasticham Posted November 3, 2009 Author Share Posted November 3, 2009 Alright, I got it working with the form and the first code, it redirects fine. However, when I added the pages that require login code to the upload.php file, the login doesn't work, it just stays on login.php. Adding the second code to the page I want to require login has stopped it redirecting for some reason. Any ideas? http://alexisarts.net/login.php I've added two users. USERNAME: withcode PASSWORD: password, doesn't redirect. USERNAME: withoutcode PASSWORD: password, does. <?php // pages that require login if(!$_SESSION['loggedIn']) { header('Location:/login.php'); exit(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/180098-login-system-with-redirect-to-specific-user-page/#findComment-950282 Share on other sites More sharing options...
JonnoTheDev Posted November 3, 2009 Share Posted November 3, 2009 <?php // pages that require login session_start(); if(!$_SESSION['loggedIn']) { header('Location:/login.php'); exit(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/180098-login-system-with-redirect-to-specific-user-page/#findComment-950286 Share on other sites More sharing options...
fantasticham Posted November 3, 2009 Author Share Posted November 3, 2009 Thanks so much for your help, man. Just one final thing, how would I code a sign out link for the upload.php file? Quote Link to comment https://forums.phpfreaks.com/topic/180098-login-system-with-redirect-to-specific-user-page/#findComment-950294 Share on other sites More sharing options...
JonnoTheDev Posted November 3, 2009 Share Posted November 3, 2009 <?php // logout.php session_start(); unset($_SESSION['loggedIn']); header('Location:/index.php'); exit(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/180098-login-system-with-redirect-to-specific-user-page/#findComment-950321 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.