Greg Donald wrote: >> define('THIS_PAGE',$_SERVER['PHP_SELF']); > > Why would you need to do this? I'd just use $_SERVER['PHP_SELF'] as is. I make frequent use of this value, so putting it in a constant saves typing and makes the page a little clearer. >> 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. The values for the session vars are set by the previous page the user visited. Each page sets these session vars, but first I transfer the values to another array in case I need to use them on that page -- eg, 1. On the page 'community.php', $_SESSION['ref_page'] is set to '/community.php'. 2. The user clicks a link to go to 'market.php'. 3. On arriving at 'market.php', $_SESSION['ref_page'] is still set to '/community.php'. I transfer this value to the $ref_page array is case I want to be able to easily refer back to the previous page. Then I reset the session vars - ie, $_SESSION['ref_page'] becomes '/market.php'. Where this is especially handy is that, if I go off to something like a intermediate page - such as a login routine, or database saving, the session vars retain the information about where the user has come from, and therefore the user can be sent back there, because on those intermediate pages I *don't* reset the session vars. >> 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'. :) Well my hosting company says it's a CGI module, so I guess they probably mean binary ;-) >> 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. I tried printing out the values before and after each of those lines. After line 53, $ref_page is an array containing precisely the values I expect, so the function is working. After line 54, the session var has been reset, as expected, to match the current page - but $ref_page has also changed and is now equal to $_SESSION['ref_page'], which is what I found very weird - ie, resetting $_SESSION['ref_page'] simultaneously reset $ref_page. I've found a workaround. Within the get_ref_page() function, I now unset the session vars after transferring their values to $ref_page. This has involved a little extra coding on those intermediate pages, because on those pages I really needed the session vars to retain their values. So I'd still like to know what's going wrong here... -- @+ Steve -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php