jbingman Posted August 30, 2007 Share Posted August 30, 2007 Hey I'm fairly new to php and i just created a user login page which works. However, I don't know how to get them to a new password requiring page after they press the submit button. How do I go about getting them there? Quote Link to comment Share on other sites More sharing options...
madspof Posted August 30, 2007 Share Posted August 30, 2007 Do you mean once they have typed in their details and pressed enter you want the user to be redirected to a page which can only be seen by some one logged in Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted August 30, 2007 Share Posted August 30, 2007 http://www.phpeasystep.com/phptu/21.html easy forgot password tutorial Quote Link to comment Share on other sites More sharing options...
jbingman Posted August 30, 2007 Author Share Posted August 30, 2007 Yeah thats exactly what i want to do. Quote Link to comment Share on other sites More sharing options...
madspof Posted August 30, 2007 Share Posted August 30, 2007 what the tutorial or my suggestion Quote Link to comment Share on other sites More sharing options...
jbingman Posted August 30, 2007 Author Share Posted August 30, 2007 your suggestion..i dont want the forgotten password. just want to know how when they enter their information they get to a page only they can see when they are logged in. Quote Link to comment Share on other sites More sharing options...
madspof Posted August 30, 2007 Share Posted August 30, 2007 Okay well how does your login work. Does it use a db or txt and is it session based or cookie based Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted August 30, 2007 Share Posted August 30, 2007 login tutorial is what you need then http://www.trap17.com/index.php/php-simple-login-tutorial_t7887.html Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 30, 2007 Share Posted August 30, 2007 You'll need to store something in the session which says they are logged in. On the page, check if the session variable is set. If not, redirect them back to the login screen. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted August 30, 2007 Share Posted August 30, 2007 jessi that tutorial above me uses sessions Quote Link to comment Share on other sites More sharing options...
jbingman Posted August 30, 2007 Author Share Posted August 30, 2007 what i have right now is... <?php $connect = mysql_connect("localhost","username","password"); $db = mysql_select_db("database"); if(isset($_POST['login'])) { if(mysql_num_rows(mysql_query("SELECT username, password FROM accounts WHERE username = '".$_POST['username']."' && password = '".$_POST['password']."' ")) >0) { if(mysql_num_rows(mysql_query("SELECT id FROM accounts WHERE username = '".$_POST['username']."' && password = '".$_POST['password']."' ")) > 0 ) { $_SESSION['logged'] = true; $_SESSION['username'] = $_POST['username']; $_SESSION['password'] = $_POST['password']; echo "<p style=\"color:green;font-size:12px\">You have successfully logged in!</p>"; }else{ //if the username and password aren't from the same account but does exist echo "<p style=\"color:red;font-size:12px\" align=\"center\"> Incorrect login! Please try again</p>"; } }else{ //username/password doesn't exist echo "<p style=\"color:red;font-size:12px\" align=\"center\">Username/Password doesn't exist!</p>"; } } ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 30, 2007 Share Posted August 30, 2007 Did you bother to look at the tutorials or research anything we said? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted August 31, 2007 Share Posted August 31, 2007 Honestly using the session tutorial will teach you alot. Quote Link to comment Share on other sites More sharing options...
jbingman Posted August 31, 2007 Author Share Posted August 31, 2007 Yes, on that one tutorial, trap17, is it possible not to use the register? because i want to be only one user login. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted August 31, 2007 Share Posted August 31, 2007 $user="abc123" pass="pass" Quote Link to comment Share on other sites More sharing options...
madspof Posted August 31, 2007 Share Posted August 31, 2007 Where you have [echo "<p style=\"color:green;font-size:12px\">You have successfully logged in!</p>";] replace that with header( 'Location: login.html' ) and that will as soon as they have login in redirect you to what ever page you want. <?php $connect = mysql_connect("localhost","username","password"); $db = mysql_select_db("database"); if(isset($_POST['login'])) { if(mysql_num_rows(mysql_query("SELECT username, password FROM accounts WHERE username = '".$_POST['username']."' && password = '".$_POST['password']."' ")) >0) { if(mysql_num_rows(mysql_query("SELECT id FROM accounts WHERE username = '".$_POST['username']."' && password = '".$_POST['password']."' ")) > 0 ) { $_SESSION['logged'] = true; $_SESSION['username'] = $_POST['username']; $_SESSION['password'] = $_POST['password']; echo header( 'Location: login.html' ); }else{ //if the username and password aren't from the same account but does exist echo "<p style=\"color:red;font-size:12px\" align=\"center\"> Incorrect login! Please try again</p>"; } }else{ //username/password doesn't exist echo "<p style=\"color:red;font-size:12px\" align=\"center\">Username/Password doesn't exist!</p>"; } } ?> And then you need to go about creating a page that checks the session to see if they you are logged in which is shown in the tutorials Quote Link to comment 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.