Page 1 of 1

PHP header function not working (urgent)

Posted: Fri Apr 08, 2005 4:16 am
by localhost
my header function is not working...it doesnt gives any error but doesn't redirects either..any clue why?

Posted: Fri Apr 08, 2005 4:41 am
by andylyon87
post some of the code for people to take look at, cos at the moment people will jus be guessing.

Here is the code

Posted: Fri Apr 08, 2005 4:46 am
by localhost

Code: Select all

session_start();
if(!isset($search))
$search=0;
if(!isset($_SESSION['auth']))
$_SESSION['auth']=0;
if(!isset($_SESSION['admin']))
$_SESSION['admin']=0;
if(!isset($_SESSION['member_type']))
$_SESSION['member_type']=4;
if(!isset($_SESSION['art_upload']))
$_SESSION['art_upload']=0;
if(!isset($_SESSION['main_id_']))
$_SESSION['main_id_']="";
if($_SESSION['admin']==0||$_SESSION['auth']==0)
header("Location : ../../index.php");

Posted: Fri Apr 08, 2005 5:04 am
by Maugrim_The_Reaper
You probably need to add the full uri to the Location: header...

i have tried that

Posted: Fri Apr 08, 2005 5:12 am
by localhost
i have tried replacing it with a full uri i.e

Code: Select all

header("Location : http://www.sdf.com/dmo/ioc/index.php");
but this didnt worked either.

Posted: Fri Apr 08, 2005 5:31 am
by JayBird
it will only redirect if

Code: Select all

$_SESSION['admin']==0||$_SESSION['auth']==0
Make sure these variables are actually what you expect...dont presume they are, echo them out

Posted: Fri Apr 08, 2005 5:36 am
by localhost
i have done that too...and as far as i know if you echo something before header() function it doesn't work... but when i did that

Code: Select all

header("location : http://www.yahoo.com") or die();
this seems to stop the page from loading...that means header function has not been excuted successfully

Posted: Fri Apr 08, 2005 5:41 am
by JayBird
localhost wrote:i have done that too...and as far as i know if you echo something before header() function it doesn't work... but when i did that
yes, i know the header function wont work if you echo before you call it, that doesn't matter, we are taking a step back to determine the variables are what you think they are

add this after your session_start() call, and post the result

Code: Select all

echo $_SESSION['admin'];

echo $_SESSION['auth']

Posted: Fri Apr 08, 2005 6:03 am
by localhost
The result is
00
which is true so it should redirect

Posted: Fri Apr 08, 2005 6:11 am
by JayBird
before the header call add...

Code: Select all

echo "i got to here";
See if the string outputs

Posted: Fri Apr 08, 2005 6:21 am
by localhost
It does ...out puts it..it seems like server is just simply ignoring the header() function

Posted: Fri Apr 08, 2005 6:24 am
by JayBird
got it!!

remove the space before the semi-colon

this

Code: Select all

header("Location : ../../index.php");
becomes

Code: Select all

header("Location: ../../index.php");

Posted: Fri Apr 08, 2005 6:29 am
by localhost
Thanks a bunch...problem solved