issues with cookies(randomly not being set)

They have: 461 posts

Joined: Jul 2003

issues with cookies(randomly not being set)

mysql db print out that i had added a row to show who has tried since the issue started and reported back to me:

mysql> select uid, username, gmt_offset,login_duration from users;
+-----+-----------------+------------+----------------+-------+
| uid | username        | gmt_offset | login_duration | issue |
+-----+-----------------+------------+----------------+-------+
|   5 | Neo             |      -5.00 |              4 |    No |
|   6 | Peaches11       |      -5.00 |              2 |       |
|   7 | Teena01         |      -5.00 |              4 |   Yes |*
|   8 | LadyAndrea      |      -5.00 |              7 |    No |
|   9 | hellokitty      |      -5.00 |              1 |    No |
|  10 | alliwantisU2    |      -5.00 |              2 |       |
|  11 | pryncessc       |      -5.00 |              2 |       |
|  12 | mickeyisagyrl   |      -5.00 |              2 |       |
|  13 | skool4zeros     |      -5.00 |              7 |    No |
|  14 | JerseyGirl      |      -5.00 |              2 |    No |
|  15 | nuclearchildren |      -5.00 |              2 |       |
|  16 | hotlilnikkie    |      -5.00 |              2 |       |
|  17 | PrincessStone   |      -5.00 |              2 |       |
|  18 | is0lati0n       |      10.00 |              7 |    No |
|  19 | Asteca          |      -5.00 |              2 |   Yes |
|  20 | Goldmaskatl     |      -5.00 |              2 |    No |
|  21 | TheNerd         |      -5.00 |              5 |    No |
|  22 | blondee         |      -5.00 |              2 |    No |
|  23 | scraps          |      -5.00 |              2 |    No |
|  24 | PurelyCanadian  |      -7.00 |              7 |    No |
|  25 | ironwarrior     |      -5.00 |              2 |       |
|  26 | Fila            |      -5.00 |              2 |    No |
|  27 | rANDOMs         |      -5.00 |              2 |       |
|  28 | AnonymousBlonde |      -5.00 |              2 |       |
|  29 | Evanescence     |      -5.00 |              2 |   Yes |
|  30 | sexyjess        |      -5.00 |              2 |    No |
|  31 | kinkycowgirl    |      -5.00 |              7 |    No |
|  32 | squigga23       |      -5.00 |              2 |       |
|  33 | Koshko          |      -5.00 |              2 |       |
|  34 | carlton_huffman |      -5.00 |              2 |       |
|  35 | felinedarkness  |      -5.00 |              2 |    No |
|  36 | Rain            |      -5.00 |              2 |       |
|  37 | vixy            |      -5.00 |              2 |    No |
|  38 | angel           |      -5.00 |              2 |   Yes |
|  39 | liciousness     |      -5.00 |              2 |    No |
|  40 | tigerpaws       |      -5.00 |              2 |       |
|  41 | coblondie       |      -5.00 |              2 |    No |
|  42 | cows_n_penguins |      -5.00 |              2 |       |
|  43 | Nephalim        |      -5.00 |              2 |       |
|  44 | m2spoild        |      -8.00 |              2 |   Yes |
|  45 | Darkened_Star   |      -5.00 |              7 |    No |
|  46 | la_izzi         |      -5.00 |              2 |    No |
|  47 | cmang           |      -5.00 |              2 |    No |
|  48 | uzaho           |      -5.00 |              2 |       |
|  49 | sterling        |      -5.00 |              2 |    No |
+-----+-----------------+------------+----------------+-------+
45 rows in set (0.00 sec)

mysql>
'# w/issues: 5
#w/out issue: 21
total reporting: 26

some of those with issues i know can use cookies because of them linking me to other sites where it works for them.

* is someone who started at 0 and i edited the db to 1, then 2 then 3 then 4 and each time it did not work.

this is the code that gets called at the begining of pages that sets cookies:

<?php
# from variables file
# login durations
$durr=array(2, 5, 15, 30, 60, (60*2), (60*24), (60*24*365*5));

# from functions file
function cookies($action){ # inserts cookies
 
include(\"/home/dcfydllc/includes/fyd.altincs.php\"); # includes file
  if(
$action=='join'){ # log in the person who just joined
   
$ims=array(); # empty array for any ims we might find unread
   
$db=mysql_connect($host, $login2, $pass2) or die(\"cannot access mysql\"); # get the
#sql connection
   
$fyd=mysql_select_db($dbname, $db) or die(\"cannot connect to db\"); # select the db
   
$un=$_POST['un']; $pw=$_POST['pw']; # what we wont change on-the-fly
   
$fprefs=mysql_query(\"SELECT uid, gmt_offset, tds, login_duration, msgs FROM users
WHERE username='
$un' AND password='$pw'\", $db); # get the prefs
    if(mysql_num_rows(
$fprefs)>0){ # we can update the cookies
     
$prefs=mysql_fetch_array($fprefs); $gmto=$prefs['gmt_offset'];
$utds=$tdc[$prefs['tds']];
     
$duration=$durr[$prefs['login_duration']]; $accepts=($prefs['msgs']*1);
$uid=$prefs['uid'];
     
$expire=(time()+($duration*60));
      setcookie('un',
$un, $expire); # set username
      setcookie('pw',
$pw, $expire); # set password
      setcookie('login', 1,
$expire); # set login
      setcookie('gmto',
$gmto, $expire); # set the gmt offset
      setcookie('utds',
$utds, $expire); # set the time display style
     
$active=gmdate(\"Y-m-d H:i:s\", time());
     
$update=mysql_query(\"UPDATE users SET last_activity='$active' WHERE
username='
$un'\", $db); # try to update users (we don't really care if it fails)
    }
  }elseif(
$action=='logout'){ # make all cookies expire
   
$expire=time()-(60*60*24*7); # set expire to 60 sec*60 min*24 hrs* 7 days ago
#(make sure a lagging computer will kill it even if my host is in new zealand)
    setcookie('un', NULL,
$expire); # makes user name expire & sets it to NULL incase
#their computer errs
    setcookie('pw', NULL,
$expire); # makes password expire & sets it to NULL incase
#their computer errs
    setcookie('login', NULL,
$expire); # makes login expire & sets it to NULL incase
#their computer errs
    setcookie('utds', NULL,
$expire); # makes the tds expire & sets it to NULL incase
#their computer errs
    setcookie('gmto', NULL,
$expire); # makes the gmt offset expire & sets it to NULL
#incase their comp errs
  }elseif(
$action=='update'){ # updates cookies (keeping you logged in) & returns waiting
#messages (optional)
    if(isset(
$_COOKIE['login'])&&($_COOKIE['login'])){ # we're logged in
     
$ims=array(); # empty array for any ims we might find unread
     
$db=mysql_connect($host, $login2, $pass2) or die(\"cannot access mysql\"); # get the
#sql connection
     
$fyd=mysql_select_db($dbname, $db) or die(\"cannot connect to db\"); # select the db
     
$un=$_COOKIE['un']; $pw=$_COOKIE['pw']; # what we wont change on-the-fly
     
$fprefs=mysql_query(\"SELECT uid, gmt_offset, tds, login_duration, msgs FROM users
WHERE username='
$un' AND password='$pw'\", $db); # get the prefs
      if(mysql_num_rows(
$fprefs)>0){ # we can update the cookies
   
$prefs=mysql_fetch_array($fprefs); $gmto=$prefs['gmt_offset'];
$utds=$tdc[$prefs['tds']];
   
$duration=$durr[$prefs['login_duration']]; $accepts=($prefs['msgs']*1);
$uid=$prefs['uid'];
   
$expire=(time()+($duration*60));
    setcookie('un',
$un, $expire); # set username
    setcookie('pw',
$pw, $expire); # set password
    setcookie('login', 1,
$expire); # set login
    setcookie('gmto',
$gmto, $expire); # set the gmt offset
    setcookie('utds',
$utds, $expire); # set the time display style
   
$active=gmdate(\"Y-m-d H:i:s\", time());
   
$update=mysql_query(\"UPDATE users SET last_activity='$active' WHERE
username='
$un'\", $db); # try to update users (we don't really care if it fails)
    if(
$accepts){ # person accepts ims
      if(
$accepts>5){ # the user wants them ALL
       
$fims=mysql_query(\"SELECT msg_id, from_un FROM msgs WHERE to_id='$uid'
AND viewed='0'\",
$db);
        while(
$gimid=mysql_fetch_array($fims)){ # while there's ims
         
$ims[]=$gimid; # record the msg_id
        }
      }else{ # user wants
$accepts amount
       
$fims=mysql_query(\"SELECT msg_id, from_un FROM msgs WHERE to_id='$uid'
AND viewed='0' ORDER BY msg_id ASC LIMIT
$accepts\", $db);
        while(
$gimid=mysql_fetch_array($fims)){ # while there's ims
         
$ims[]=$gimid; # record the msg_id
        }
      }
    }
      }
    } # end cookie updating
    return
$ims;
  }
}
?>
nearly every page calls cookies. the ones that dont are some of the signup and the logout (which calls logout instead)

i haven't been able to find a pattern or errror in the cookies call. i figure i'm missing something. any pointers to what's causing this would be greatly appreciated.

note: php edited to prevent scrolling

POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

I don't see anything wrong...

You may want to try something like this:

<?php
}elseif($action=='update'){ # updates cookies (keeping you logged in) & returns waiting messages (optional)
$dbug = 'a';
    if(isset(
$_COOKIE['login'])&&($_COOKIE['login'])){ # we're logged in
$dbug .= 'b';
     
$ims=array(); # empty array for any ims we might find unread
     
$db=mysql_connect($host, $login2, $pass2) or die(\"cannot access mysql\"); # get the sql connection
     
$fyd=mysql_select_db($dbname, $db) or die(\"cannot connect to db\"); # select the db
     
$un=$_COOKIE['un']; $pw=$_COOKIE['pw']; # what we wont change on-the-fly
     
$fprefs=mysql_query(\"SELECT uid, gmt_offset, tds, login_duration, msgs FROM users WHERE username='$un' AND password='$pw'\", $db); # get the prefs
      if(mysql_num_rows(
$fprefs)>0){ # we can update the cookies
$dbug .= 'c';
   
$prefs=mysql_fetch_array($fprefs); $gmto=$prefs['gmt_offset']; $utds=$tdc[$prefs['tds']];
   
$duration=$durr[$prefs['login_duration']]; $accepts=($prefs['msgs']*1); $uid=$prefs['uid'];
   
$expire=(time()+($duration*60));
    setcookie('un',
$un, $expire); # set username
    setcookie('pw',
$pw, $expire); # set password
    setcookie('login', 1,
$expire); # set login
    setcookie('gmto',
$gmto, $expire); # set the gmt offset
    setcookie('utds',
$utds, $expire); # set the time display style
echo \"\n\n<!-- DBUG - DBUG - DBUG - DBUG - DBUG\n\n\";
echo \"dbug=
$dbug\n\";
echo \"prefs=\"; print_r();
echo \"duration=
$duration\n\";
echo \"time=\".time().\"\n\";
echo \"expire=
$expire\n\";
echo \"un=
$un\n\";
echo \"pw=
$pw\n\";
echo \"login=
$login\n\";
echo \"gmto=
$gmto\n\";
echo \"utds=
$utds\n\";
echo \"\n\nDBUG - DBUG - DBUG - DBUG - DBUG -->\n\n\";
?>
This should give you a picture of what's going on.

The "abc" should probably go right before the return statement. It's purpose is to indicate if any of the conditionals are failing.

Yes, I know how to spell debug. I just felt like saving time by ommiting all the e's. Wink

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 461 posts

Joined: Jul 2003

thanx mark. i wasn't sure how to go about debugging ti. but i found it interesting that one of those with issues earlier didn't have themtonight. makes me feel that there is something on the user side. that and the fact the more i have try it, the more that have it work. it's looking more and more like user side and not client side. i'm going to wait on the added debug until i've had a chance to make sure every one of them has double checked that cookies are allowed by their browser.

you are the first response i got. =o)
so far the only one. so the only reason i'm not doing the debug now is laziness

POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

Sounds good.

I still don't see anything wrong with the logic. The only way I find things at that point is by printing every $var I can find to see if any values are not what I expected them to be at that point.

Something else just came to mind... are you doing anything with remote_addr or remote_ip? 'Cause AOL's proxies impare use of those $vars for authentication proceedures. (I don't see the proxies effecting cookies, but who knows - it's a-o-hell)

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 461 posts

Joined: Jul 2003

the irony being that since the last post two that don't use aol went and looked at my quirks section of the faq explaining how to turn on cookies, and viola, it worked. therefore i think it's safe to say now that its either ao-hell for the two iknow are aol users, and browser issues for the rest... i think the one that it didn't work when i changed things recently put on a firewall. i rember her saying something about that, so her firewall might be the isue there. i know zone alarms doesn't allow cookies unless you tell it to (the advanced version) becasue my dad hs it

POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.

They have: 461 posts

Joined: Jul 2003

one of the ones using aol... she uses their browser. i don't know enough about it and said it may be a failure of the browser, and that i know it doesn't understand standards right anyway. the response was that she asked which one i reccommend using. once she started using mozilla it was fine for her.

POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.