Re: [PHP] Weird sessions problem
Andre Dubuc wrote: I gather that all of the script occurs on one page, and that the page is 'refreshed' by some action of the user (i.e. that the user has clicked/entered login info on some other page, and that this page then needs to detect that change.) No, it's when moving from one page/script to another. What may be happening is that the refresh action triggers the script twice: once for the initial loading and again for the reset values. Hence, $ref_page gets reset by line 53 ($ref_page = get_ref_page(); Nope. There's no 'refresh' as such. Another question, by any chance, are you switching into https by any chance? Nope. Ah well. As I mentioned earlier, I have a workaround now - not ideal, but as it's working it'll do. I don't make money from web programming so I'll leave it at that and get on with my day job :-) -- @+ Steve -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Weird sessions problem
On Sun, 28 Nov 2004 13:14:54 +0100, steve [EMAIL PROTECTED] 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
Re: [PHP] Weird sessions problem
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
Re: [PHP] Weird sessions problem
On Sunday 28 November 2004 22:46, steve wrote: 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. Is $ref_page getting set to what the _previous_ value of $_SESSION['ref_page'] was? If so, it sounds like you have register_globals enabled. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* I think we're in trouble. -- Han Solo */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Weird sessions problem
Jason Wong wrote: On Sunday 28 November 2004 22:46, steve wrote: 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. Is $ref_page getting set to what the _previous_ value of $_SESSION['ref_page'] was? If so, it sounds like you have register_globals enabled. No to both. When I arrive at the new page, the sessions vars (as expected) contain the values set by the previous page. $ref_page is not set. The values are transferred to $ref_page by the function. That works as planned. I then reset the value of the session vars, at which point, $ref_page also gets set. From printing out the values after each line, I find this: Let's say we've come from the page /community.php and have arrived at /market.php. Here are the values at each stage: $_SESSION['ref_page] = '/community.php' $_SESSION['ref_pagequery'] = 'pagemode=index' // as an example 53. $ref_page = get_ref_page(); $ref_page['name'] = '/community.php' $ref_page['query'] = 'pagemode=index' $_SESSION['ref_page] = '/community.php' $_SESSION['ref_pagequery'] = 'pagemode=index' 54. $_SESSION['ref_page'] = THIS_PAGE; $ref_page = '/community.php' // now a scalar $_SESSION['ref_page] = '/market.php' register_globals is off (in php.ini and there are no .htaccess files). -- @+ Steve -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Weird sessions problem
On Sunday 28 November 2004 05:46 pm, steve wrote: Jason Wong wrote: On Sunday 28 November 2004 22:46, steve wrote: 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. Is $ref_page getting set to what the _previous_ value of $_SESSION['ref_page'] was? If so, it sounds like you have register_globals enabled. No to both. When I arrive at the new page, the sessions vars (as expected) contain the values set by the previous page. $ref_page is not set. The values are transferred to $ref_page by the function. That works as planned. I then reset the value of the session vars, at which point, $ref_page also gets set. From printing out the values after each line, I find this: Let's say we've come from the page /community.php and have arrived at /market.php. Here are the values at each stage: $_SESSION['ref_page] = '/community.php' $_SESSION['ref_pagequery'] = 'pagemode=index' // as an example 53. $ref_page = get_ref_page(); $ref_page['name'] = '/community.php' $ref_page['query'] = 'pagemode=index' $_SESSION['ref_page] = '/community.php' $_SESSION['ref_pagequery'] = 'pagemode=index' 54. $_SESSION['ref_page'] = THIS_PAGE; $ref_page = '/community.php' // now a scalar $_SESSION['ref_page] = '/market.php' register_globals is off (in php.ini and there are no .htaccess files). -- @+ Steve Hi Steve, As a late-comer to this thread, I'd like to toss about a few ideas. I gather that all of the script occurs on one page, and that the page is 'refreshed' by some action of the user (i.e. that the user has clicked/entered login info on some other page, and that this page then needs to detect that change.) What may be happening is that the refresh action triggers the script twice: once for the initial loading and again for the reset values. Hence, $ref_page gets reset by line 53 ($ref_page = get_ref_page(); I experienced the same difficulty once, and essentially solved the problem by adding an extra page that is called, by a simple switch statement, if there is a change: i.e, from 'community' to 'market'. Another question, by any chance, are you switching into https by any chance? Hth, Andre -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Weird sessions problem
On Monday 29 November 2004 06:46, steve wrote: No to both. When I arrive at the new page, the sessions vars (as expected) contain the values set by the previous page. $ref_page is not set. The values are transferred to $ref_page by the function. That works as planned. I then reset the value of the session vars, at which point, $ref_page also gets set. From printing out the values after each line, I find this: Let's say we've come from the page /community.php and have arrived at /market.php. Here are the values at each stage: $_SESSION['ref_page] = '/community.php' $_SESSION['ref_pagequery'] = 'pagemode=index' // as an example 53. $ref_page = get_ref_page(); $ref_page['name'] = '/community.php' $ref_page['query'] = 'pagemode=index' $_SESSION['ref_page] = '/community.php' $_SESSION['ref_pagequery'] = 'pagemode=index' 54. $_SESSION['ref_page'] = THIS_PAGE; $ref_page = '/community.php' // now a scalar $_SESSION['ref_page] = '/market.php' register_globals is off (in php.ini and there are no .htaccess files). The only thing that I can think of that will cause such behaviour (that is setting $_SESSION['xyz'] will change $xyz) is the register_globals setting being enabled. If you're certain that this is not the case I suggest that you post some *concise* code that illustrates the problem so that others can test whether they can reproduce what you're seeing. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* Besides, I think Slackware sounds better than 'Microsoft,' don't you? -- Patrick Volkerding */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php