Forum Moderators: coopster
Users on my site currently use a form to log in with, but there's no 'Remember Me' feature, something I'd like to add.
I'd like the globally included configuration file to check if a user's logged in, and if not, try to log them in from a cookie the user would have opted to set on their previous login. The cookie would hold the user's encrypted username and password, and I'd like for those to be sent to the login script (a seperate file). Is there anyway to simulate an HTTP POST with the cookie info?
I suspect header() might do it, but how exactly? Has anyone done this before?
Thanks for any help,
Alex ...
I suspect that what you have is some kind of "login.php" script that renders the form and then authenticates the credentials and starts a session (or however you are doing it).
What you want to do is separate the authentication code out of that script and store it in a separate include file, say "authenticate.inc".
If you include "authenticate.inc" at the top of every page of the secure part of your site (maybe you have a common header script?) then it can automatically authenticate either the username/password from your login.php script _or_ a cookie containing the credentials.
The logic within authenticate.php is simple:
if (!$in_session)
{
if ($_POST["username"])
{
// authenticate username/password and start session
}
elseif ($_COOKIE["credentials"]
{
// authenticate cookie and start session
}
if (!$in_session)
{
header("Location: login.php");
exit();
}
...where $in_session is just some variable that you know will be set if you have an authenticated users. The neat thing about this is that your users can bookmark pages from your protected area.