Jump to content

Recommended Posts

So, I took a break at this for a bit, but I'm back to solving my situation... So, I need to put together user permissions to certain pages. 

 

$sql="SELECT * FROM $tbl_name WHERE username='$username' and password='$password'"; 

$result=mysql_query($sql); 
$access=$result['access'];

$count=mysql_num_rows($result); 

if($count==1){ 

session_start(); 
$_SESSION["rdz_logged"] = $access; 
header("location:../members.php"); 
} 
else { 
echo "<div align=center>The username and password you have provided are incorrect.<br>";
echo 'Return to <a href="../login.php">Login</a></div>';

} 

 

session_start(); 
if(($_SESSION['rdz_logged'] != admin) || ($_SESSION['rdz_logged'] != pkg1) || ($_SESSION['rdz_logged'] != pkg2) || ($_SESSION['rdz_logged'] != pkg3) || ($_SESSION['rdz_logged'] != sales)){ header("Location: login.php"); }

 

So, do you see what I'm trying to do?  Should this work?

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

So, I have tried it, and it's giving me weird results.  My session is registered, but it doesn't give me access like I had hoped.  I'm questioning this part... does this make sense to you?

 

$_SESSION["rdz_logged"] = $access; 

 

I've changed this code to have quotes... but still not working, any thoughts?

session_start();
if(($_SESSION['rdz_logged'] != 'admin') || ($_SESSION['rdz_logged'] != 'pkg1') || ($_SESSION['rdz_logged'] != 'pkg2') || ($_SESSION['rdz_logged'] != 'pkg3') || ($_SESSION['rdz_logged'] != 'sales')){ header("Location: login.php"); }

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/173930-user-permissions/#findComment-917057
Share on other sites

it's still not allowing the session to register... I'm directed to my login page every time. 

 

Is there a better way to do this:

session_start();
if(($_SESSION['rdz_logged'] != 'admin') && ($_SESSION['rdz_logged'] != 'pkg1') && ($_SESSION['rdz_logged'] != 'pkg2') && ($_SESSION['rdz_logged'] != 'pkg3') && ($_SESSION['rdz_logged'] != 'sales')){ header("Location: login.php"); }

Link to comment
https://forums.phpfreaks.com/topic/173930-user-permissions/#findComment-917074
Share on other sites

echo your session and see whats stored in it. there are better ways of doing permissions tho, check out bitwise operators. check out this page http://www.litfuel.net/tutorials/bitwise.htm and scroll to the bottom to see how the guy set up a permissions system. however if you don't want to overhaul your whole permission system what you have will work, but echo out the session variable to see if what you think is there is there

 

Link to comment
https://forums.phpfreaks.com/topic/173930-user-permissions/#findComment-917077
Share on other sites

hmm... it didn't return anything...

 

So, in my table I have a column called 'access'... shouldn't this bring up the value for the  same user?

$sql="SELECT * FROM $tbl_name WHERE username='$username' and password='$password'";
$result=mysql_query($sql); 
$access=$result['access'];

Link to comment
https://forums.phpfreaks.com/topic/173930-user-permissions/#findComment-917079
Share on other sites

Apologies if I am way off here but I didn't read the rest of the thread. I just notice you aren't fetching the results from the db.

 

$sql="SELECT * FROM $tbl_name WHERE username='$username' and password='$password'";
$result=mysql_query($sql);
$row = mysql_fetch_assoc($result);
$access=$row['access'];

Link to comment
https://forums.phpfreaks.com/topic/173930-user-permissions/#findComment-918449
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.