This is a discussion on problem with cookie within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I have a problem with a cookie (what a news? :-)) I have a site with 2 different authentication levels. A ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I have a problem with a cookie (what a news? :-)) I have a site with 2 different authentication levels. A generic user level and an admin level. I would save this level in a cookie after the user has inserted username and passwd so I can retrieve it in the pages and showing contents accordingly. these are the two codes. this is the code to set the cookie ==CODE START if($passcheck['passwd'] == md5($_POST['passwd'])) { setcookie('auth',$passcheck['auth']); echo "<p>You are a known user<br>\n"; echo "Authorized at level: " . $passcheck['auth'] . "</p>\n"; echo "<p><a href=\"../start.php\">Click here to proceed.</a></p>\n"; } else { ..... ==CODE END and this is the code at beginning of start.php page ==CODE START <?php $auth = $_COOKIE['auth']; ?> ==CODE END ....the problem is the cookie is set correctly, but both $auth and $_COOKIE['auth'] are empty. I cannot understand where the problem is. Thank you in advance. -- Best regards, Stefano Tessarin To follow the path: look to the master, follow the master, walk with the master, see through the master, become the master. Zen poem. |
|
|||
|
Stefano Tessarin írta:
> > I have a problem with a cookie (what a news? :-)) > > I have a site with 2 different authentication levels. A generic user > level and an admin level. > I would save this level in a cookie after the user has inserted username > and passwd so I can retrieve it in the pages and showing contents > accordingly. > > these are the two codes. > > this is the code to set the cookie > ==CODE START > if($passcheck['passwd'] == md5($_POST['passwd'])) > { > setcookie('auth',$passcheck['auth']); > echo "<p>You are a known user<br>\n"; > echo "Authorized at level: " . $passcheck['auth'] . "</p>\n"; > echo "<p><a href=\"../start.php\">Click here to > proceed.</a></p>\n"; > > } else { ..... > ==CODE END > > > and this is the code at beginning of start.php page > > ==CODE START > <?php > $auth = $_COOKIE['auth']; > ?> > ==CODE END > > ...the problem is the cookie is set correctly, but both $auth and > $_COOKIE['auth'] are empty. > I cannot understand where the problem is. > > Thank you in advance. > You should set cookies before anything else is sent, 'cause cookies are sent in the header section in http. |