I put "username" and "password" to a form of mine. The action starts up a handler.php. The user sees then only a white page (handler.page) if he does not reload his browser at handler.php. If he does, the handler puts him to back to index.php.
I would like to put the user automatically back to the homepage after being at handler.php where he gets a login -cookie.
I have the following in my handler.php
$email = $_POST['email'];
$username = $_POST['username'];
$passhash_md5 = $_POST['passhash_md5'];
// COOKIE setting
/* $cookie may look like this
variables
$username = "username"$
$passhash_md5 = "password"$
$email ="email"$
$_SERVER['REMOTE_ADDR']=11.44.23.94$
before md5:$
"usernamepasshash_md5email11.44.23.94"$
after md5:$
"a08d367f31feb0eb6fb51123b4cd3cb7"$
*/
$login_cookie = md5(
$username .
$password .
$email .
$_SERVER['REMOTE_ADDR']
);
setcookie ("login", $login_cookie);
if (isset($_COOKIE['login']) )
{
$sql2 = "SELECT * from users";
$raw_user_list = pg_query($dbconn, $sql2);
$user_list = pg_fetch_all($raw_user_list);
// to process each user in the user-list that has a password
foreach ($user_list as $user => $passhash_md5)
{
//match the user list with the cookie$
if ( $login_cookie == $_COOKIE['login'] )
{
header("Location: index.php");
die("logged in");
}
}
header("Location: index.php");
die("wrong username/password");
}
?>
I have a form which uses the POST -method and the action is handler.php.
My form
<form method="post" action="handler.php">
<p>Username:
<input name="username" type="text" size="40" />
</p>
<p>Email:
<input name="email" type="text" size="230" />
</p>
<p>Password:
<input name="password" type="password" size="230" />
</p>
<input type="submit" value="OK" />
</form>
The handler page is not being called by AJAX.
I run the handler page unsuccessfully with the HEAD:
<head>
<meta http-equiv="refresh" content="5; URL=inedx.php">
</head>
However, I cannot include the HEAD because PHP does not allow to have output when you use header -commands.
How can you put the user automatically to the index.php if the login is successful?