problem with cookie

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 ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-01-2005
Stefano Tessarin
 
Posts: n/a
Default problem with cookie


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.

Reply With Quote
  #2 (permalink)  
Old 04-02-2005
Sebestyén Dénes
 
Posts: n/a
Default Re: problem with cookie

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.
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

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



All times are GMT +1. The time now is 08:43 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0