PHP header function not working (urgent)

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
localhost
Forum Commoner
Posts: 43
Joined: Tue Dec 07, 2004 4:52 am
Location: islamabad
Contact:

PHP header function not working (urgent)

Post by localhost »

my header function is not working...it doesnt gives any error but doesn't redirects either..any clue why?
andylyon87
Forum Contributor
Posts: 168
Joined: Sat Jan 31, 2004 5:31 am
Location: Dundee

Post by andylyon87 »

post some of the code for people to take look at, cos at the moment people will jus be guessing.
localhost
Forum Commoner
Posts: 43
Joined: Tue Dec 07, 2004 4:52 am
Location: islamabad
Contact:

Here is the code

Post 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");
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

You probably need to add the full uri to the Location: header...
localhost
Forum Commoner
Posts: 43
Joined: Tue Dec 07, 2004 4:52 am
Location: islamabad
Contact:

i have tried that

Post 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.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
localhost
Forum Commoner
Posts: 43
Joined: Tue Dec 07, 2004 4:52 am
Location: islamabad
Contact:

Post 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
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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']
localhost
Forum Commoner
Posts: 43
Joined: Tue Dec 07, 2004 4:52 am
Location: islamabad
Contact:

Post by localhost »

The result is
00
which is true so it should redirect
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

before the header call add...

Code: Select all

echo "i got to here";
See if the string outputs
localhost
Forum Commoner
Posts: 43
Joined: Tue Dec 07, 2004 4:52 am
Location: islamabad
Contact:

Post by localhost »

It does ...out puts it..it seems like server is just simply ignoring the header() function
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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");
localhost
Forum Commoner
Posts: 43
Joined: Tue Dec 07, 2004 4:52 am
Location: islamabad
Contact:

Post by localhost »

Thanks a bunch...problem solved
Post Reply