Cooper94 Posted December 15, 2008 Share Posted December 15, 2008 Ok I am createing a login script that will determine if the user is user_level 0 , 1 , and or 2. Now this is what I have and it dosnt seem to work: checking user_level <? session_start(); include 'session_checker.php'; session_checker(); if ($_SESSION['user_level'] = 0){ echo 'user links'; } if ($_SESSION['user_level'] = 2){ echo 'admin links'; } ?> checkuser.php <? session_start(); header("Cache_control: private"); include 'db.php'; // Convert to simple variables $username = $_POST['username']; $password = $_POST['password']; if((!$username) || (!$password)){ echo "Please enter ALL of the information! <br />"; include 'login_form.php'; exit(); } // check if the user info validates the db $sql = mysql_query("SELECT * FROM users WHERE username='$username' AND PASSWORD='$password'"); $login_check = mysql_num_rows($sql); if($login_check > 0){ while($row = mysql_fetch_array($sql)){ foreach( $row AS $key => $val ){ $$key = stripslashes( $val ); } // Register some session variables! session_register('name'); $_SESSION['name'] = $name; session_register('email_address'); $_SESSION['email_address'] = $email_address; session_register('username'); $_SESSION['username'] = $username; session_register('password'); $_SESSION['password'] = $password; session_register('user_level'); $_SESSION['user_level'] = $user_level; mysql_query("UPDATE users SET last_login = now() WHERE username='$username'"); mysql_close($connection); echo("your in"); } } else { echo "You could not be logged in! Either the username and password do not match or you have not registered with us!<br /> Please try again!<br />"; include 'login_form.php'; } ?> Any help is much greatful. Thank You Quote Link to comment https://forums.phpfreaks.com/topic/136979-user-levels/ Share on other sites More sharing options...
xtopolis Posted December 15, 2008 Share Posted December 15, 2008 if ($_SESSION['user_level'] = 0){ echo 'user links'; } if ($_SESSION['user_level'] = 2){ echo 'admin links'; } needs to be if ($_SESSION['user_level'] == 0){ echo 'user links'; } if ($_SESSION['user_level'] == 2){ echo 'admin links'; } = -> assign value == -> compare values also, session_register() is depreciated.. you can take the lines with that out, it's fine just having: $_SESSION['name'] = $name; $_SESSION['email_address'] = $email_address; etc. Quote Link to comment https://forums.phpfreaks.com/topic/136979-user-levels/#findComment-715458 Share on other sites More sharing options...
Cooper94 Posted December 15, 2008 Author Share Posted December 15, 2008 Thank you and not to be a pain but is it possible to: <? session_start(); if ($_SESSION['user_level'] == 0){ echo '<center><a href="">File Pirep</a><br><a href="">File LOA</a><br><a href="">Edit Profile</a><br><a href="">Roster</a></center>'; } if ($_SESSION['user_level'] == 0 AND 2){ echo '<center>Staff Options</center>'; echo '<center><a href="">Waiting Approval</a><br><a href="">View Pireps</a><br><a href="">Active Pilots</a></center>'; } ?> see if it is both? " 0 AND 2" thank you Quote Link to comment https://forums.phpfreaks.com/topic/136979-user-levels/#findComment-716102 Share on other sites More sharing options...
premiso Posted December 15, 2008 Share Posted December 15, 2008 Please use the [ code] tags (without the initial space) to paste code in. <?php session_start(); if ($_SESSION['user_level'] == 0){ echo '<center><a href="">File Pirep</a><br><a href="">File LOA</a><br><a href="">Edit Profile</a><br><a href="">Roster</a></center>'; }elseif ($_SESSION['user_level'] == 2){ echo '<center>Staff Options</center>'; echo '<center><a href="">Waiting Approval</a><br><a href="">View Pireps</a><br><a href="">Active Pilots</a></center>'; } ?> What are you trying to get of the "AND" 2 ? What is 2 suppose to be checking against? The second if statement does not make any sense. I think what I posted above is what you are trying to do? Quote Link to comment https://forums.phpfreaks.com/topic/136979-user-levels/#findComment-716106 Share on other sites More sharing options...
9three Posted December 15, 2008 Share Posted December 15, 2008 Your 2nd if statement does not have logic. But if you want it that way anyway: if ($_SESSION['user_level'] == 0 && 2){ echo '<center>Staff Options</center>'; echo '<center><a href="">Waiting Approval</a><br><a href="">View Pireps</a><br><a href="">Active Pilots</a></center>'; } That means that BOTH have to match otherwise it returns false. If you want one or the other to pass as true then use: if ($_SESSION['user_level'] == 0 || 2){ echo '<center>Staff Options</center>'; echo '<center><a href="">Waiting Approval</a><br><a href="">View Pireps</a><br><a href="">Active Pilots</a></center>'; } && = AND || = OR Quote Link to comment https://forums.phpfreaks.com/topic/136979-user-levels/#findComment-716111 Share on other sites More sharing options...
premiso Posted December 15, 2008 Share Posted December 15, 2008 Your 2nd if statement does not have logic. But if you want it that way anyway: && = AND || = OR Just an FYI, AND and OR work the same as && and || both are acceptable in PHP. Quote Link to comment https://forums.phpfreaks.com/topic/136979-user-levels/#findComment-716115 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.