Page 1 of 1

Undefined offsets

Posted: Mon May 18, 2009 6:40 pm
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;
 

Re: Undefined offsets

Posted: Mon May 18, 2009 7:00 pm
by Benjamin
An array index in either $cookieInfo or $loginInfo does not exist.

Re: Undefined offsets

Posted: Mon May 18, 2009 7:15 pm
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];
 

Re: Undefined offsets

Posted: Mon May 18, 2009 7:28 pm
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.