Jump to content

header not working


davidannis
Go to solution Solved by mac_gyver,

Recommended Posts

I am trying to redirect to the login page if a user is not logged in. I have the following piece of code:

    $slashpos=  strrpos($_SERVER['SCRIPT_NAME'], '/');
    $path=substr($_SERVER['SCRIPT_NAME'],0,($slashpos+1));
    header('Location: '. $_SERVER['HTTP_HOST'].$path.'login.php?message=This%20page%20is%20only%20for%20gallery%20personnel');
    //echo 'Location: '. $_SERVER['HTTP_HOST'].$path.'login.php?message=This%20page%20is%20only%20for%20gallery%20personnel';
    exit('');

If I execute the script as is I get nothing - a blank page.

 

If I uncomment the echo line I get:

Location: localhost:8888/Art3/theme/login.php?message=This%20page%20is%20only%20for%20gallery%20personnel

which seems right to me.

 

I have the following lines at the top of the script and I'm getting no errors

ini_set('display_errors', 1);
error_reporting(0);

I have tried:

just using 'Location: login.php?message=foo' and

constructing the URL from $_SERVER['SERVER_NAME'] and $_SERVER['SERVER_PORT']

 

Link to comment
Share on other sites

Adding http:// makes no difference

 

Setting Error Reporting to E_ALL gives me warnings about undeclared variables and undefined indexes followed by an error because the header was already sent. error_reporting(E_ERROR); results in the same blank screen.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.