Page 1 of 1

php header location couldn't jump to correct page

Posted: Sun Jun 14, 2009 3:16 pm
by anthor

Code: Select all

<?php
if (isset($_POST['login'])){
require_once('Connections/Conn.php');
mysql_select_db($database_Conn, $Conn);
$username = $_POST['username'];
$password = $_POST['password'];
$query_rs_post = sprintf("SELECT * FROM web_user WHERE username='%s' AND password='%s'",$username,$password);
$rs_post = mysql_query($query_rs_post, $Conn) or die(mysql_error());
$totalRows_Recordset1 = mysql_num_rows($rs_post);
mysql_free_result($rs_post);
    if ($totalRows_Recordset1 > 0){
    //echo 'login success';
    setcookie("gsbay_username", $username,time()+60*60*24*999);
    setcookie("gsbay_password", $password,time()+60*60*24*999);
    header("location:index.php");
    }else{
    echo 'login no';
    }
}
?>
when the login button are pressed will execute this code,but when success login the page will refresh mean this line code
header("location:index.php");
unfortunately,it will jump to a "The page cannot be displayed", and i have checked the url,it is correct..why man?

Re: php header location couldn't jump to correct page

Posted: Sun Jun 14, 2009 9:14 pm
by Dale
Hello,

Firstly try putting a space between the ":" and the "index.php" bit.

Code: Select all

header("Location: index.php");
Oh and if you run into any "cannot modify header information" when using the header location redirection, then just after the opening PHP put ob_start() there.

Code: Select all

<?php
ob_start();
 
// Your code below
Some of that may help. =]

Re: php header location couldn't jump to correct page

Posted: Mon Jun 15, 2009 2:56 am
by miro_igov
Looks like redirection loop, do you have code on index.php which checks for valid login and if none redirects to login page?