Jump to content

Simple user log-in script error


garethuk

Recommended Posts

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.