Forum Moderators: coopster

Message Too Old, No Replies

Cookie Query...

How do I store a particular user level in a cookie

         

woldie

4:26 pm on May 3, 2004 (gmt 0)

10+ Year Member



Hi There,

I'm creating a admin system and what I have is a cookie based login system which works well.

However when the user sucessfully logins in I set them a cookie, but I want to store the user level in a cookie so for instance if that person has a user level set to 1 they will get certain menu items appearing in the main nav.

How do I go about doing this?

Heres some code...

// authorisation code
$result=mysql_query("select user_level from tablename
where userid='$user'
AND password=password('$pass')");

$num=mysql_num_rows($result);

if ($num!= 0)
{
// want to set user level in cookie
$cookie_name = 'auth';
$cookie_value = 'ok';
setcookie ($cookie_name,$cookie_value, time()+3200);


header("Location: main-menu.php");
exit;
}
else
{
header("Location:index.html");
exit;
}

main-menu.php

// displays the menu items.

// checks for cookie
if ($auth == 'ok')
{
// but also check the value of user level here I think
// displays menu items
}

else
{
include('redirect.php');
}

This will be implemented throughout the site because I have a main nav at the top of each page but the nav will display certain menu items depending on value of user level in the cookie.

Thanks for your help :o)

WhosAWhata

12:27 am on May 4, 2004 (gmt 0)

10+ Year Member



just add
setcookie("USERLEVEL",$level);
after you change $level

and call it like $_COOKIE['USERLEVEL']

woldie

8:06 am on May 4, 2004 (gmt 0)

10+ Year Member



Thanks WhosAWhata

That works well, cheers for yer help....

:o)

Warboss Alex

4:37 pm on May 5, 2004 (gmt 0)

10+ Year Member



But people could mess with your cookies this way ..

Timotheos

5:31 pm on May 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



But people could mess with your cookies this way ..

That's the way the cookie crumbles..

Sorry, couldn't help myself ;-)

Best to use sessions in this case.