Jump to content

User Levels


Cooper94

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/136979-user-levels/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/136979-user-levels/#findComment-715458
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/136979-user-levels/#findComment-716102
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/136979-user-levels/#findComment-716106
Share on other sites

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

 

Link to comment
https://forums.phpfreaks.com/topic/136979-user-levels/#findComment-716111
Share on other sites

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.