RE: Upgrade PHP 4.3.4 to PHP 5.0.3 (Windows 2k & IIS5), I recieve a Blank Page and Session errors

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The $_SESSION['sitedoc'] was not initialized because I use
$_SERVER["PATH_TRANSLATED"] to make the requires for diffrent files. In
these file I initialized this $_SESSION varibales. I already took care for
this ploblem (in PHP5 you have to replace it for ORIG_PATH_TRANSLATED).
But I still have the blank page, with no error or wrnings.
The only thing that look strange is that the session files in sessiondata
are beeing created empty.
Do u know what can it be?
Thanks a lot

Fabian

-----Original Message-----
From: Richard Lynch [mailto:ceo@xxxxxxxxx]
Sent: Miércoles, 09 de Febrero de 2005 06:01 p.m.
To: Fabian I. Cuesta
Cc: php-general@xxxxxxxxxxxxx
Subject: Re:  Upgrade PHP 4.3.4 to PHP 5.0.3 (Windows 2k & IIS5), I
recieve a Blank Page and Session errors


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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux