dean7 Posted October 31, 2009 Share Posted October 31, 2009 Hi all, for my website i have a members area only which on members can veiw, but at the moment anyone can veiw them pages. Is there any way in which i can stop them veiwing the page without registering? Thanks Link to comment https://forums.phpfreaks.com/topic/179724-members-only/ Share on other sites More sharing options...
waynew Posted October 31, 2009 Share Posted October 31, 2009 How do you know if a person is logged in or not? Are you using sessions? If not, you should be looking into sessions. Link to comment https://forums.phpfreaks.com/topic/179724-members-only/#findComment-948275 Share on other sites More sharing options...
dean7 Posted October 31, 2009 Author Share Posted October 31, 2009 Well at the moment im useing $logged['username']. But ive tryed: if ($logged['username'] = '') { echo ("Your Not Logged In!"); }else{ echo ("Welcome $logged['username']"); But that didnt seem to work Link to comment https://forums.phpfreaks.com/topic/179724-members-only/#findComment-948277 Share on other sites More sharing options...
Jnerocorp Posted October 31, 2009 Share Posted October 31, 2009 try one of these maybe im not an expert but but i know some php if ($logged['username'] == '') { echo ("Your Not Logged In!"); }else{ echo ("Welcome $logged['username']"); if ($_SESSION['username'] == '') { echo ("Your Not Logged In!"); }else{ echo ("Welcome $_SESSION['username']"); Link to comment https://forums.phpfreaks.com/topic/179724-members-only/#findComment-948282 Share on other sites More sharing options...
dean7 Posted October 31, 2009 Author Share Posted October 31, 2009 if ($logged['username'] == '') { echo ("Your Not Logged In!"); }else{ echo ("Welcome $logged['username']"); Worked thanks, But now the users that arnt logged in carnt see the members area, but the users who logged in carnt see it either. It just shows a blank white screen. Link to comment https://forums.phpfreaks.com/topic/179724-members-only/#findComment-948283 Share on other sites More sharing options...
Jnerocorp Posted October 31, 2009 Share Posted October 31, 2009 <?php if ($logged['username'] == '') { //Put stuff in here the the users who are not logged in will see echo "Your not logged in ... login now!"; }else{ //Put stuff in here the the users who are logged in will see $username = $logged['username']; echo "You are logged in $username welcome to the private area"; ?> <b> You can put html between "? >" and "< ?php" </b> <?php } ?> You need to put the content that the logged in user can see between the "else { }" Link to comment https://forums.phpfreaks.com/topic/179724-members-only/#findComment-948287 Share on other sites More sharing options...
dean7 Posted October 31, 2009 Author Share Posted October 31, 2009 It still shows the white page :S Link to comment https://forums.phpfreaks.com/topic/179724-members-only/#findComment-948288 Share on other sites More sharing options...
Jnerocorp Posted October 31, 2009 Share Posted October 31, 2009 ok I just thought of a simpler way of doing this use this code if(isset($logged['username'])) { $username = $logged['username']; //Display stuff here that logged in users will see echo "Welcome to the logged in area $username"; } also post your page code so I can see it -John Link to comment https://forums.phpfreaks.com/topic/179724-members-only/#findComment-948291 Share on other sites More sharing options...
waynew Posted October 31, 2009 Share Posted October 31, 2009 When a person logs in, you have to give them a session variable. So, once they've entered a correct username and password, you could do this: $_SESSION['username'] = $username_from_db; Then on protected pages, check to see if the session variable 'username' exists: if(!isset($_SESSION['username'])){ header('Location: login.php'); exit; } Link to comment https://forums.phpfreaks.com/topic/179724-members-only/#findComment-948378 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.