php header location couldn't jump to correct page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
anthor
Forum Newbie
Posts: 3
Joined: Sun Jun 14, 2009 3:13 pm

php header location couldn't jump to correct page

Post 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?
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

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

Post 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. =]
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

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

Post 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?
Post Reply