Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/130221-solved-login-page-loops-to-itself/
Share on other sites

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!';
}

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.