jamesxg1 Posted January 30, 2009 Share Posted January 30, 2009 how do i make this code see if the user is logged in or not and if they arent then it displays what i need in the ECHO area ? <?php if($_SESSION['groupid'] == ' ') { echo("CONTENT THAT I NEED ONLY GUESTS ON MY SITE TO SEE"); } ?> Link to comment https://forums.phpfreaks.com/topic/143138-solved-php-if-guest-statment/ Share on other sites More sharing options...
gevans Posted January 30, 2009 Share Posted January 30, 2009 That's a very small amount of code for us to determine the return variable from you user management. Link to comment https://forums.phpfreaks.com/topic/143138-solved-php-if-guest-statment/#findComment-750691 Share on other sites More sharing options...
jamesxg1 Posted January 30, 2009 Author Share Posted January 30, 2009 That's a very small amount of code for us to determine the return variable from you user management. ok what do u need to know and i will post the code ? Link to comment https://forums.phpfreaks.com/topic/143138-solved-php-if-guest-statment/#findComment-750692 Share on other sites More sharing options...
gevans Posted January 30, 2009 Share Posted January 30, 2009 What value gets assigned to what variable once you know a user is who he says he is via a login form Link to comment https://forums.phpfreaks.com/topic/143138-solved-php-if-guest-statment/#findComment-750693 Share on other sites More sharing options...
kittrellbj Posted January 30, 2009 Share Posted January 30, 2009 if isset($_SESSION['groupid']) { // protected content... } else { echo "You must be logged in to view this page."; } A better way to do it would be a negative test at the beginning. Test to see if the person is not logged in and echo, if it passes that test, then display content. if (!isset($_SESSION['groupid'])) // if there is no "group id" set, then... { echo "You must be logged in to view this page."; exit(); // This line is "What happens if not logged in", // so, you can use exit() or a redirect or whatever. } else { // Protected content } The second one lets you use it in an include at the top of the page a little easier if you're designing a large site. Link to comment https://forums.phpfreaks.com/topic/143138-solved-php-if-guest-statment/#findComment-750694 Share on other sites More sharing options...
jamesxg1 Posted January 30, 2009 Author Share Posted January 30, 2009 if isset($_SESSION['groupid']) { // protected content... } else { echo "You must be logged in to view this page."; } A better way to do it would be a negative test at the beginning. Test to see if the person is not logged in and echo, if it passes that test, then display content. if (!isset($_SESSION['groupid'])) // if there is no "group id" set, then... { echo "You must be logged in to view this page."; exit(); // This line is "What happens if not logged in", // so, you can use exit() or a redirect or whatever. } else { // Protected content } The second one lets you use it in an include at the top of the page a little easier if you're designing a large site. Worked!, Thanks mate James. Link to comment https://forums.phpfreaks.com/topic/143138-solved-php-if-guest-statment/#findComment-750698 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.