Re: Weird sessions problem

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

 



On Sun, 28 Nov 2004 13:14:54 +0100, steve <php@xxxxxxxxxxxxx> wrote:
> I have a routine that uses sessions vars to hold the details of the previous
> page, so I can bounce back to it if necessary. But I'm having some weird
> problems with it. In the page I have the following (line numbers included
> to get you an idea of where these things come):
> 
> 17. require_once(INC_PATH."i_std_cfg.phtml");
> 
> (this include file includes the following:)
> 
> define('THIS_PAGE',$_SERVER['PHP_SELF']);

Why would you need to do this?  I'd just use $_SERVER['PHP_SELF'] as is.

> function get_ref_page() {
>   /* Retrieves the details of the last page which will have set
>      the session vars referred to */
>   $ref_page = array();
>   if(isset($_SESSION['ref_page'])) {
>     $ref_page['name'] = $_SESSION['ref_page'];
>     if(isset($_SESSION['ref_pagequery'])) {
>       $ref_page['query'] = $_SESSION['ref_pagequery'];
>     }
>   }
> return $ref_page;
> }
> 
> Now back in the main page:
> 
> 53. $ref_page = get_ref_page(); // now reset session vars to current page

I wouldn't use the same variable names like this.  You have a local
$ref_page, and a $_SESSION variable called 'ref_page'.  While if done
correctly it will work, you only encourage errrors this way.

> 54. $_SESSION['ref_page'] = THIS_PAGE;
> 55. $_SESSION['ref_pagequery'] = $_SERVER['QUERY_STRING'];

I don't follow the need to call a function just to figure out what
$_SESSION variables are already there and available for use.  You seem
to be making this more complex that it needs to be.  I would just use
the variable where they exists already.

> Now, on my local system (PHP 4.3.4) this all works fine. On the live system
> (PHP 4.1 - with PHP run, I believe, as CGI module)

PHP can be built as a 'cgi binary' or as a web server 'module', I've
never heard of a 'cgi module'.  :)

> I hit a problem. At line
> 53, $ref_page is an array containing the values I expect. After line 54,
> $ref_page is now a scalar containing the value of THIS_PAGE. It's almost as
> though line 54 has been executed before line 53... Help!

Is the function returning what you think it is?  print_r() before the return.


-- 
Greg Donald
Zend Certified Engineer
http://gdconsultants.com/
http://destiney.com/

-- 
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