xProteuSx Posted October 27, 2008 Share Posted October 27, 2008 I am trying to figure out whether this is do-able: Login.php has a hidden function (call it 'function-login') which takes 2 variables (username, password). On the original visit to this page, no sessions are loaded hence username=null and password=null. GET username; GET password; if (username==' ' || pass==' ') { display login form with two boxes for username and password action = refresh this page with new variables from the login boxes } else { check that password and username match in DB if (everything checks out) { Yay, you're logged in! } else { You entered a password/username combo that does not exist } } Can this be done? Going from login.php -> login.php? I usually see login.php -> authorize.php -> welcome.php How would I set up a function for this? Many thanks. Quote Link to comment https://forums.phpfreaks.com/topic/130221-solved-login-page-loops-to-itself/ Share on other sites More sharing options...
Jeremysr Posted October 27, 2008 Share Posted October 27, 2008 Yes, I do this all the time. The code would be something like this: // This will execute after they submit the form, going to this page again if ($_POST) { // Check username and password, log them in if (password_is_correct($_POST['username'], $_POST['password'])) { $_SESSION['loggedin'] = true; } else { echo "Error: Wrong password.<br />"; } } // Print log in form if they're not logged in, otherwise print success message if (!$_SESSION['loggedin']) { echo '<form method="post" action="login.php"> ... </form>'; } else { echo 'You have been logged in successfully!'; } Quote Link to comment https://forums.phpfreaks.com/topic/130221-solved-login-page-loops-to-itself/#findComment-675366 Share on other sites More sharing options...
xProteuSx Posted October 27, 2008 Author Share Posted October 27, 2008 Great! Thanks for your response. I have it figured out now, and have this working on my site. Thanks very much for letting me know its possible. It saves me time! I've tried things without asking before, only to spend hours and hours of my time trying to do something that can't be done (like trying to get the visitors screen resolution solely through php). lol. Hindsight is a bitch! PHP is server side! Duh! Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/130221-solved-login-page-loops-to-itself/#findComment-675426 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.