|
Posted by Richard Lynch on 02/09/05 23:00
Fabian I. Cuesta wrote:
> Hi, I'm trying to upgrade the PHP version of my dev enviroment.
> After installing PHP5 I've just recieve a blank page. I activated the
> error
> log of PHP and recieve a couple of errors like this one:
>
> [09-Feb-2005 13:38:20] PHP Notice: Undefined index: sitedesc in
> c:\Inetpub\wwwroot\Inpae\admin\lib\headerFooter.php on line 40
>
> All related to $_SESSION, like the values are not set (sitedesc is one of
> the indexes of the variable $_SESSION)
But when you first start a session, a totally NEW session, is
$_SESSION['sitedoc'] initialized?
I assume not.
Your problem code looks something like this:
<?php
session_start();
if ($_SESSION['sitedoc']){
//whatever;
}
?>
PHP is notifying you that there is NO session index named 'sitedoc' yet,
but you're trying to read it and use the value -- the value that doesn't
exist.
You'll need to get in the habit of writing (and re-writing) code like this:
<?php
session_start();
if (isset($_SESSION['sitedoc']) && $_SESSION['sitedoc']){
//whatever
}
?>
You may also re-structure your code a bit if 'sitedoc' can take on several
values, so it ends up being more like:
<?php
session_start();
if (isset($_SESSION['sitedoc'])){
if ($_SESSION['sitedoc'] == 'whatever'){
}
elseif ($_SESSION['sitedocd'] == 'something else'){
}
}
?>
The point is that you shouldn't be "reading" session variables that were
never set to any value at all in the first place.
Sure, PHP will initialize them to 0 or '' or false, but the point here is
to catch typos where you have:
if ($_SESSION['sietdoc']){
}
else{
}
If you RARELY expect 'sitedoc' to be a TRUE value, and you don't do a lot
of unit testing, a typo bug like this could go undetected for a lonnnnng
time.
The PHP Notice warns you about things like this by not notifying you when
you try to read a variable that hasn't been set.
> Notice: C:\Inetpub\wwwroot\Inpae\lib\include.php line 15 - Undefined
> index:
> SCRIPT_NAME
> Notice: C:\Inetpub\wwwroot\Inpae\lib\include.php line 15 - Undefined
> index:
> PATH_TRANSLATED
See above.
> Debug Warning: C:\Inetpub\wwwroot\Inpae\lib\include.php line 3 -
> main(/config.php) [<a href='function.main'>function.main</a>]: failed to
> open stream: No such file or directory
> Compile Error: C:\Inetpub\wwwroot\Inpae\lib\include.php line 3 - main()
> [<a
> href='function.require'>function.require</a>]: Failed opening required
> '/config.php' (include_path='.;c:\php5\pear')
config.php is not in the same directory as your script, nor in the PEAR
library. It is, probably, in Inpae\lib\ and you need to change your
include_path setting in .htaccess or in the script or somewhere to have
that directory in your include path.
--
Like Music?
http://l-i-e.com/artists.htm
Navigation:
[Reply to this message]
|