Forum Moderators: coopster
$page = "users/$user.html"; // replace with you page
header("Location:$page");
or, you could use a
echo "<body onload=\"window.location='$page'\">";
or
echo "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"0; URL=$page\">";
or of course you could
include("$page");
as you can see, there are many ways using PHP or HTML to redirect
Is the login script, which is on a page of it's own, then I use
$page = "centre.php";
echo "<body onload=\"window.location='$page'\">";
As the forwarding script, but if I put it anywhere except on it's own after the login script, it does not work.
if(mysql_num_rows($result) > 0) { // this indicates success
$logged_in_user = $user;
session_register("logged_in_user");
$page = "centre.php";
} else { // this indicates login error
$page = "loginerror.php";
}
header [ca.php.net]("Location: $page");
that should work, though both of those pages would have to be located in the site root. Otherwise the paths will have to adjusted.
<?
if($user && $pass) {
if($logged_in_user == $user) {
echo $user.",you are already logged in.";
exit;
}
$db = mysql_connect("*******", "*****", "*******");
mysql_select_db("users", $db);
$result = mysql_query("SELECT * FROM users WHERE name = '".$user."' AND password = PASSWORD('".$pass."')");
if(!$result) {
echo "Sorry, there has been a technical error.";
exit;
}
if(mysql_num_rows($result) > 0) {
$logged_in_user = $user;
session_register("logged_in_user");
$page = "centre.php";
} else {
$page = "loginerror.php";
}
}
echo "<body onload=\"window.location='$page'\">";
?>
But it is keeps trying to reload the same page (login.php) rather than continuing to the base page.
<?
if($user && $pass) {
if($logged_in_user == $user) {
echo $user.",you are already logged in.";
exit;
}
$db = mysql_connect("*", "*", "*");
mysql_select_db("users", $db);
$result = mysql_query("SELECT * FROM users WHERE name = '".$user."' AND password = PASSWORD('".$pass."')");
if(!$result) {
echo "Sorry, there has been a technical error.";
exit;
}
if(mysql_num_rows($result) > 0) {
$logged_in_user = $user;
session_register("logged_in_user");
$page = "centre.php";
} else {
$page = "loginerror.php";
}
}
header("Location: $page");
?>
if ($user && $pass) {
...yaddayadda...
} else {
$page = "login.php";
}
...if you will be continuing to use the secondary redirection rather than including the redirection in the qualifying login routine.
if(mysql_num_rows($result) > 0) {
$logged_in_user = $user;
session_register("logged_in_user");
header("Location: centre.php");
exit;
} else {
header("Location: loginerror.php");
exit;
}
(Without exiting from the routine after redirecting, PHP will continue to "walk" the page, possibly messing with something else.)
:)