Jump to content

[SOLVED] help me fix these syntax errors...


kaiman

Recommended Posts

thing is, `level` is coming out of the db as a string, and using === is returning false because you are comparing a string to an integer.

 

you can either do this:

 

$_SESSION['level'] = (int)$level; //adding (int) will turn the numeric value from a string into an integer;

 

then, === would return true;

 

-OR-

 

if ($_SESSION['level'] == '1') {

 

compare $_SESSION['level'] to a numeric string retaining == as your comparable operator.

Yes! Finally got it working, he he!

 

FYI, I changed my session stuff to this to get it to run correctly:

 

if ($_SESSION['level'] == '1') {

 

Thanks mrMarcus and others for all your help!

 

The next question is - How do I do a check to make sure that regular users can't see admin pages, etc. So far I have this basic session check:

 

<?php
session_start();
if(!isset($_SESSION['username'])){
header("Location: http://www.example.com/login/" );
exit;
}
?>

 

How would I check for levels? Would something like this work?

 

<?php
// admin session check
session_start();
if(!isset($_SESSION['username'])){
header("Location: http://www.example.com/login/" );
exit;
}
else ($_SESSION['level'] < 4) {
   echo "You Don't Have Permission to View an Admin Page"; exit (0);
}
?>

 

or do I need to pull the array from the db and register the $_SESSION 'level' again?

 

Thanks a ton!

 

kaiman

Yes, that should work fine, I would advise casting to an integer before comparing to one with the less than operator.

 

session_start();
if (!isset($_SESSION['username']))
{
   header('Location: http://www.example.com/login/');
   exit;
}
if ( (int)$_SESSION['level'] < 4)
{
   die('You do not have permission to view an Admin page');
}

 

I would also advise you to rethink the level you have set for banned users. Or atleast direct them to a banned page, echo an explanation of why they have been banned and destroy their session upon login.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.