mlj0102 Posted May 1, 2012 Share Posted May 1, 2012 I have an issue I am not sure how to solve. What I want to do is to make sure authentication has already occurred . Or that my $currentMember is set and it if is set for an IF statement to do nothing.. However it it is not set for a redirect to the home page with no echo statements or anything to that nature just a redirect. Am I even close? <?php include( ABSOLUTE_PATH . 'class/database.class.php' ); include( ABSOLUTE_PATH . 'class/person.class.php' ); //Start Session session_start(); $currentMember = unserialize($_SESSION['currentMember']); $db = new Database; $person = new Person($currentMember->memberid); if ( $auth_satus == 0 ) { header('Location:' . APP_ROOT . 'index.php'); } exit(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/261871-redirect-to-home-page-if-not-logged-on/ Share on other sites More sharing options...
marcus Posted May 1, 2012 Share Posted May 1, 2012 Why don't you just do if(!$_SESSION['currentMember']){ // redirect } Quote Link to comment https://forums.phpfreaks.com/topic/261871-redirect-to-home-page-if-not-logged-on/#findComment-1341836 Share on other sites More sharing options...
leitning Posted May 1, 2012 Share Posted May 1, 2012 Not sure why that wouldn't work for you. A header redirect only works if nothing else has been sent to the browser yet, so the only thing I can think of is something in your include files or your class constructors that's posting to the browser before you get a chance to redirect. If that's the case though you should get a warning. Is it possible it's not working because you're checking the value of $auth_satus instead of $auth_status? Also should $auth_status belong to something, ie $person->auth_status? On a side note you're probably better off using individual session variables to track your member than a serialized object. Quote Link to comment https://forums.phpfreaks.com/topic/261871-redirect-to-home-page-if-not-logged-on/#findComment-1341871 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.