Undefined offsets

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gsteele
Forum Newbie
Posts: 2
Joined: Mon May 18, 2009 6:33 pm

Undefined offsets

Post by gsteele »

I'm new to PHP, but trying to revive an old script. I keep getting the following error message related to cookies and do not understand what is wrong. The first is the error and the second is the acutal script that it refers to.
Notice: Undefined offset: 0 in /home/www/dentonwatch/functions.php on line 17

Notice: Undefined offset: 1 in /home/www/dentonwatch/functions.php on line 17

Notice: Undefined offset: 2 in /home/www/dentonwatch/functions.php on line 17

Notice: Uninitialized string offset: 12 in /home/www/dentonwatch/functions.php on line 15

Code: Select all

 
09 $cookieInfo = array();
10  $i = 0;
11  $arrayi = 0;
12
13  while ($i < strlen($loginInfo))
14  {
15    while (($loginInfo[$i] !== '-') AND ($i < strlen($loginInfo)))
16    {
17      $cookieInfo[$arrayi] = $cookieInfo[$arrayi].$loginInfo[$i];
18     $i++;
19    } // end while
20  $i++;
21  $arrayi++;
22  } // end while
23
24  return $cookieInfo;
 
Last edited by Benjamin on Mon May 18, 2009 6:59 pm, edited 1 time in total.
Reason: Added [code=php], [quote] tags.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Undefined offsets

Post by Benjamin »

An array index in either $cookieInfo or $loginInfo does not exist.
gsteele
Forum Newbie
Posts: 2
Joined: Mon May 18, 2009 6:33 pm

Re: Undefined offsets

Post by gsteele »

thanks for the quick response. Here is the log in cookie parsing. Is this where the problem lies?

Code: Select all

 
      $cookieInfo = parseCookieInfo($loginInfo);
      $loginID = $cookieInfo[0];
      $loginType = $cookieInfo[1];
 
Last edited by Benjamin on Mon May 18, 2009 7:25 pm, edited 1 time in total.
Reason: Added [code=php] tags.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Undefined offsets

Post by Benjamin »

Please use

Code: Select all

when posting code in the forum.  You'll need to research how arrays work to solve your problem.  One method is to use isset() to check if a variable exists before you try to retrieve it's value, but this may not solve your problem because the code may expect that they are all set, which would mean there is an issue elsewhere in the code.
Post Reply