Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The PHP header() function is not redirecting [closed]

I am using the following PHP code to check a session. But if the session is not logged into then the page is not redirected and just shows the black page.

My if condition is right! It is hitting the header function...

Here is my code:

if(
    !isset($_SESSION['SESS_MEMBER_ID'])
    || (trim($_SESSION['SESS_MEMBER_ID']) == '')
    AND !isset($fb_login)
) {
    header("location:login.php?msg=Please+Login+Again.");
}

How can I fix it?

HTTP/1.1 200 OK
Date: Wed, 10 Oct 2012 10:57:14 GMT
Server: Apache/2.2.15 (CentOS)
X-Powered-By: PHP/5.3.3
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8
like image 790
Sandeep Kamble Avatar asked Dec 05 '25 04:12

Sandeep Kamble


1 Answers

If you're using header("Location: "); after you've output content make sure you've put ob_start(); earlier in the script. ob_start(); buffers your script, so nothing is output until you either call ob_end(); or the end of the file is reached. Calling header("Location: "); after content has already been output to the browser can cause problems.

like image 65
EM-Creations Avatar answered Dec 07 '25 19:12

EM-Creations



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!