davidannis Posted January 15, 2016 Share Posted January 15, 2016 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'] Quote Link to comment Share on other sites More sharing options...
requinix Posted January 16, 2016 Share Posted January 16, 2016 Stick the "http://" in there too. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted January 16, 2016 Share Posted January 16, 2016 error_reporting(0); that stops the reporting of all errors. that should be - error_reporting(E_ALL); Quote Link to comment Share on other sites More sharing options...
davidannis Posted January 16, 2016 Author Share Posted January 16, 2016 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. Quote Link to comment Share on other sites More sharing options...
Solution mac_gyver Posted January 16, 2016 Solution Share Posted January 16, 2016 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. Quote Link to comment Share on other sites More sharing options...
davidannis Posted January 17, 2016 Author Share Posted January 17, 2016 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.