Reply
User Level Block
Old 01-26-2005, 09:50 PM User Level Block
Junior Talker

Posts: 2
I have posted here for help with my user system here before and gotten my answers from you guys so I thought I would ask this here..

I'm wanting to deny users that do not have the right user level from a document. I have tried several different ways of doing this but none of them seem to work. Here is what I tired last..

PHP Code:
<? session_start();//resume the session

include 'db.php';

$username $_SESSION['username'];

$sql_level_check mysql_query("SELECT user_level FROM users WHERE username='$username'");

$level_check mysql_num_rows($sql_level_check);

if(
$level_check 0)
{
  echo 
"You have acess to this file!";
}
else
{
  die(
"<b>You do not have access to this file!.</b>");//kick em out!
}      ?>
I have also tried using the session for the user level but it didn't seem to work either.
Retard is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 01-27-2005, 04:21 AM
Ultra Talker

Posts: 377
First of all, where would user input his name? I mean there should be a form. So maybe you should use $_GET or $_POST or $_REQUEST?
Second, you'll need to read a value from a db, that contains userss and their levels. mysql_num_rows wouldn't return a level, it will return a nuber of a strings, that are a result of a query. Try to use:
$level_check=mysql_fetch_array($sql_level_check);
if($level_check["level"]) { ... and so on
__________________
andrews_john
www.softwareforhosting.com
andrews_john is offline
Reply With Quote
View Public Profile Visit andrews_john's homepage!
 
Old 01-28-2005, 01:40 PM
Novice Talker

Posts: 8
Yeah and to do it affectively use MYSQL_NUM instead of MYSQL_ASSOC. MYSQL_ASSOC is marginally faster and more precise, but MYSQL_NUM is still the best choice. Also, that script SHOULD have worked if your session carried over from when he logged in..maybe you should use cookies. And that include syntax is wrong I think..it should be include ("./filename"). But too make it more secure, you should do (instead of resuming the session)

if (isset($_SESSION['username'])) { //Do REST

i think thats your problem, man. I can spot a lot of errors. On the line where it wont let you in:

die("<b>You do not have access to this file!.</b>")

Use an ob_start at the top, so you can call a header function anywhere in the script, and then add a header below the die, leading back to the main page (redirection). After the header use ob_end_clean and then ob_end_flush to send the data to the web. Okay?
Robotical World is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to User Level Block
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.11758 seconds with 12 queries