Jump to content
Sign in to follow this  
davidannis

header not working

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']

 

Share this post


Link to post
Share on other sites
error_reporting(0);

 

 

that stops the reporting of all errors.

 

that should be -

error_reporting(E_ALL);

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

the error about the header() ... states that some output was sent to the browser and on what line all or the end of that output was at, that's preventing the header() from working. you would need to find and fix what is causing that output.

Share this post


Link to post
Share on other sites

The header was sent because of a blank line at the end of an included php file and because of the warning messages. Once I got rid of both the blank line and the warnings it works. Thank you all for the help.

Share this post


Link to post
Share on other sites

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.

Sign in to follow this  

×
×
  • 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.