I have a log-in form on a webpage and I want users to be able to log-in or register. At the top of the page I have the PHP script with the conditional testing for which submit button was pressed. The Log-in portion works fine. The "Register" portion works (meaning, it gets into the if-statement), but it doesn't redirect to my register.php site. Any thoughts?
I've tried changing the order of the if/elseif statements but to no avail. I get no warnings from this script, but it just reloads the page rather than redirecting to register.php.
To see the actual webpage, go here.
<?php
$error = '';
session_start();
ob_start();
if (isset($_POST['register'])) {
header("http://www.mynextbit.com/authenticate/register.php");
}
elseif (isset($_POST['login'])) {
session_start();
$username = trim($_POST['username']);
$_SESSION['user'] = $username;
$password = trim($_POST['pwd']);
// location to redirect on success
$redirect = 'http://www.mynextbit.com/Pages/newtemplateTEST.php';
require_once('../includes/authenticate_mysqli.inc.php');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
...
And, the HTML FORM...
<?php
if ($error) {
echo "<p>$error</p>";
}
if (!$_SESSION['user']) { ?>
<font color="red"><i><userlogin>Please Log In</userlogin></i></font><br />
<form id="form1" method="post" action="" style="margin-left: 15px">
<label for="username" ><font size="-1">Username:</font></label>
<input type="text" name="username" id="username">
<br />
<label for="pwd"><font size="-1">Password:</font></label>
<input type="password" name="pwd" id="pwd">
<br />
<input name="login" type="submit" id="login" value="Log in" style="display:inline"> or
<input name="register" type="submit" id="register" value="Register" style="display:inline">
</form>
<?php } ?>
Check out here. http://php.net/manual/en/function.header.php
Use the header with the location as like this header('Location: http://www.example.com/');
header('Location:http://www.mynextbit.com/authenticate/register.php');
It should work.
Thanks