By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,853 Members | 2,144 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,853 IT Pros & Developers. It's quick & easy.

PHP $_COOKIE is never empty... why?

luke14free
P: 79
Hello,
I think to have some problem because that code, that is done in order to decide if the page has to have inside the login form (-->user not yet logged) or not(-->user logged).
[PHP]
<?php
setcookie ("autorizzazione", "", time()-60000);
//check if the user is logged yet
//include ("functions.php");
if (empty($HTTP_COOKIE_VARS)){
include "login.html";
echo "2";
}else{
//defineaut();
echo "1";
}
?>
[/PHP]
when is executed runs always "1"...

It means that i have some cookie on my pc but i have deleted manually everyone, and set destroy cookie in line 2...I tried also with

[PHP]
if (isset($_COOKIE)){
[/PHP]
and
[PHP]
if (isset($_COOKIE['autorization'])){
[/PHP]
instead of line 5...Is it normal??

In another page i set the cookie in this way:
[PHP]
setcookie('autorization','2');
[/PHP]
and it seems to be ok...Could someone please help me? (my server has PHP 5 and global var ON)
Thanks,
Kind Regards, luke14free
May 23 '07 #1
Share this Question
Share on Google+
4 Replies


pbmods
Expert 5K+
P: 5,821
Changed thread title to better match contents.

Try using print_r($_COOKIE) to see what's in there (such as PHPSESSID, for example).
May 23 '07 #2

luke14free
P: 79
Yes, thanks for the immediate answer,,,
(don't worry for the post name! feel always free to make changes! =] )
[PHP]
Array ( [autorizzazione] => [82a3f464d4f908ca02a63aae2c0f0647] => 8c9120502c94ad80924b75afff9936ec [mosvisitor] => 1 )
[/PHP]
that's what i get,,,but the cookie should be empty!!! Is it a bug?
May 23 '07 #3

Atli
Expert 5K+
P: 5,058
Yes, thanks for the immediate answer,,,
(don't worry for the post name! feel always free to make changes! =] )
[PHP]
Array ( [autorizzazione] => [82a3f464d4f908ca02a63aae2c0f0647] => 8c9120502c94ad80924b75afff9936ec [mosvisitor] => 1 )
[/PHP]
that's what i get,,,but the cookie should be empty!!! Is it a bug?
There may always be some extra data in your $_COOKIE array, such as Session ID's (PHPSESSIONID) or something like that.
In your case there seemes to be a cookie named [mosvisitor], tho I dont know what that is.
It's never a good idea to assume the $_COOKIE array is empty.

The best way to use Cookies like this is to check for a specific cookie. I've successfully done this with some of my projects.
Expand|Select|Wrap|Line Numbers
  1. if(isset($_COOKIE['mycookie'])) {
  2.   // User is logged in
  3. }
  4. else {
  5.   // User is not logged in
  6. }
  7.  
May 24 '07 #4

luke14free
P: 79
I wrote in my original post, in an horrible english that i have already tried to code that way but the result is always the same.
May it be a server-side problem?
thanks
May 24 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.