garethuk Posted August 16, 2011 Share Posted August 16, 2011 Hi all, I have a basic member login script working on my website. Currently, if the user isn't logged in they cannot see certain pages and get redirected to access-denied.php by the following script: <?php //Start session session_start(); //Check whether the session variable SESS_MEMBER_ID is present or not if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID']) == '')) { header("location: access-denied.php"); exit(); } ?> However, I am trying to amend this code so that if the user isn't logged in they can see the page but cannot see various elements of the page. Therefore, instead of sending a user to the access-denied.php page, I want to set a variable in the above code which I can then compare with elsewhere on the page (to decide whether to show a certain paragraph for example). I have got this far... <?php //Start session session_start(); //Check whether the session variable SESS_MEMBER_ID is present or not if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID']) == '')) { $logged_in = "no"; } ?> As a test to see if it works I then put the following later in the file... <?php if ($logged_in = "no") echo 'Not logged into website'; else echo 'Logged into website'; ?> However, the output always comes through as "Not logged into website", even though I have logged in. Can anybody see what the problem is? Quote Link to comment https://forums.phpfreaks.com/topic/244918-simple-user-log-in-script-error/ Share on other sites More sharing options...
trq Posted August 16, 2011 Share Posted August 16, 2011 You use == to compare values in php, not = Quote Link to comment https://forums.phpfreaks.com/topic/244918-simple-user-log-in-script-error/#findComment-1258097 Share on other sites More sharing options...
garethuk Posted August 16, 2011 Author Share Posted August 16, 2011 That was quick! Thanks so much, that solved it. Quote Link to comment https://forums.phpfreaks.com/topic/244918-simple-user-log-in-script-error/#findComment-1258102 Share on other sites More sharing options...
Clarkeez Posted August 16, 2011 Share Posted August 16, 2011 When I was learning the basics, this page helped me greatly. Check it out http://www.w3schools.com/php/php_operators.asp Quote Link to comment https://forums.phpfreaks.com/topic/244918-simple-user-log-in-script-error/#findComment-1258199 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.