Page 1 of 1

header() question

Posted: Tue Feb 13, 2007 11:09 pm
by speedy33417
I'm getting stuck with a header issue. I have a login page at mysite.com/login.php and I'd like to direct any unathorized access to this page from any part of the site.
My problem is if the user tries to see mysite.com/something/page.php
and finds this script:

Code: Select all

if (!isset($_SESSION['userName']) && !isset($_SESSION['userId']))
{
	header('Location: http://www.mysite.com/login.php');
	exit();
}
Once the user's redirected I expected it to jump directly to mysite.com/login.php, however somehow it only includes the script from login.php but stays in the something folder.
I don't have absolut urls in the login.php script meaning that any images used on that page are broken and won't load, because they have the wrong path.

Is there a quick fix to this problem?

Do I need to change everything to absolut urls or can I do something to phisically jump to mysite.com/login.php?

Posted: Tue Feb 13, 2007 11:15 pm
by iknownothing
does ../login.php work?

Posted: Tue Feb 13, 2007 11:25 pm
by speedy33417
Yeah I tried that too and that gives me a HTTP request error...

Posted: Tue Feb 13, 2007 11:49 pm
by Kieran Huggins
do you have a .htaccess file with anything in it? (in either the root or the 'something' folder?)

Re: header() question

Posted: Wed Feb 14, 2007 1:06 am
by B.Murali Krishna
use ob_start(); at starting of that page to initiate header's.

Regards
Murali
speedy33417 wrote:I'm getting stuck with a header issue. I have a login page at mysite.com/login.php and I'd like to direct any unathorized access to this page from any part of the site.
My problem is if the user tries to see mysite.com/something/page.php
and finds this script:

Code: Select all

if (!isset($_SESSION['userName']) && !isset($_SESSION['userId']))
{
	header('Location: http://www.mysite.com/login.php');
	exit();
}
Once the user's redirected I expected it to jump directly to mysite.com/login.php, however somehow it only includes the script from login.php but stays in the something folder.
I don't have absolut urls in the login.php script meaning that any images used on that page are broken and won't load, because they have the wrong path.

Is there a quick fix to this problem?

Do I need to change everything to absolut urls or can I do something to phisically jump to mysite.com/login.php?

Posted: Wed Feb 14, 2007 7:39 am
by feyd
Output buffering is not a solution to header() problems.

Posted: Wed Feb 14, 2007 7:46 am
by superdezign
Try using $_SERVER['DOCUMENT_ROOT'] if you having a problem with which folder your being redirected in.