I’ve searched on this and I’m still not sure. In asp.net, I can programmatically login a user on the server side…and I’m not talking about a client-side script that fills in the forms automatically when they pull up the site. I can check something server-side and, if true, log them into the site. If false I can redirect to a user name/password form and make them type in the user name and password.
Is it possible to do something similar in PHP?
I have something I would like to do, but it sure would be nice not to waste time on something if it isn’t even possible to begin with
Thanks!
-=-=-=
In asp.net the process works like this:
- call uservalidate method to see if the credentials are correct
- call formsauthentication.setauthcookie to set the authentication cookie
- redirect user to predetermined page
e.g.,
Response.Cookies.Remove(FormsAuthentication.FormsCookieName);
FormsAuthentication.SetAuthCookie("username", false);
Response.Redirect("samepage.aspx");
Only on the redirect does the ticket get processed.
Sure it can – you need to read up on PHP Sessions.
You accept the user’s credentials via a standard POST request sent from a form.
Take the credentials and check if they match (usually by querying a DB).
If they do, set a session variable to indicate the user has authenticated (
$_SESSION['user_is_authenticated'] = true);Check in your subsequent pages that needs to be secured if the user is authenticated or not – if he’s not, redirect to login page:
if (!$_SESSION['user_is_authenticated']) header('location:login.php');