Jump to content

Recommended Posts

I have many pages i want to only be accessed by an admin when they are logged in, at the moment they are accessed by anyone logged in or not, this is a big problem if someone figured out the right url so i been trying to only make them accessible if the right variables exist.

 

i have tried many thing but none of them seems to work, i have no idea why as they look right to me

attempt 1

session_start();
$admin = 'FALSE';

if (isset ($_SESSION['user_level']) && ($_SESSION['user_level'] == '5'))
{
$admin = 'TRUE';
}

if($admin = 'FALSE')
{
echo '<span style="color:#F00; text-align:center; font-size:14px;">Unauthorized Access Attempt!</span>';
  exit;
}

if ($admin = 'TRUE')
{

###my script here###

}

 

attempt 2

session_start();

if (isset ($_SESSION['user_level']) && ($_SESSION['user_level'] == '5'))
{

###my script here###

}else
{
echo '<span style="color:#F00; text-align:center; font-size:14px;">Unauthorized Access Attempt!</span>';
}

 

any ideas? all i want is it too check if the user level is 5 (which is my admin level) and if so allow access to the page, if not give and echo message.

 

Thank you.

Link to comment
https://forums.phpfreaks.com/topic/245187-check-session-variables/
Share on other sites

A coupel of things here:

 

1. You use Strings to state whetehr something is true or false. Boolean values woudl serve you better.

 

2. Where you have put if($admin = 'FALSE') and if($admin = 'TRUE'). You are actually assigning these values rather than testing them for equality. Cange them to if($admin == 'FALSE') and if($admin == 'FALSE').

 

Let me know how you get on!

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.