Page 1 of 1

PHP session variable not being transferred

Posted: Tue Apr 01, 2008 7:07 pm
by michaelh613
I have a PHP session variable that is not being transferred to a new page. I have verified it is being populated correctly
the variable is _SESSION['equidatauri'].

As you can see below I have tested it by using the echo command in testing to verify the correct value (which is a url) is being populated.

Code: Select all

 
$_SESSION['equidatauri'] = $uri;
 
 
$_SESSION['condition'] = $condition;
//echo "<br>The session url in thankyou.php to go to is " .$_SESSION['equidatauri']."<br>";
//echo "about to redirect header <br>";
echo "redirecting to Location: http://xyzdomain.com/secure/thanks.php <br>";
 
on thanks.php I have the following code

Code: Select all

 
<?php
session_start();
//ob_start();
set_time_limit(120);
$debug=1;
foreach( $_SESSION as $key => $value ){
    if( !isset(${$key}) ){  // Don't clobber existing values
    ${$key} = $value;
    }
    if ($debug == 1) {
     echo "<P>$key => $value<P>\n"; //testing
    }
    }
    
    
 
$condition=$_SESSION['condition'];
echo "<br>The session url in thanks.php to go to is " .$_SESSION['equidatauri']."<br>";
echo "condition is $condition<br>";
 
$equidatauri=$_SESSION['equidatauri'];
 
Again I have used the echo command to print out the individual variable and iterated through allthe $_SESSION VALUES are displayed. It shows as being an empty field.

equidatauri =>
condition => Error


The session url in thanks.php to go to is
condition is Error

The variable url in thankyou.php to go to is

I've done some addtional testing where I hardcode

Code: Select all

 
$uri="http://test.com";
 
and the informed is moved over correctly in the session variable.

My real URL is a very large dynamically generated one. Is there a size limit on the value of the URL? (I have verified the session variable is intitially populated correctly but loses that value when it moves t the new page. Is there away around this problem if it is size related.

The reason I move to a new page is to make sure the PHP on this page does not run a 2nd time if the page is refreshed (it inserts data into a database when i keep my html page on this with the PHP.


I appreciate any help you can give me.

Re: PHP session variable not being transferred

Posted: Tue Apr 01, 2008 7:44 pm
by Christopher
Do you have a session_start(); on the first page?

Re: PHP session variable not being transferred

Posted: Tue Apr 01, 2008 7:47 pm
by michaelh613
arborint wrote:Do you have a session_start(); on the first page?
Yes I do. I've edited my original post (I guess while you were asking your question) to note sessions are being moved correctly. If I hardcode my initial variabel the URL is moved over with a small URL and the problem only occurs with a large one. So I'm wondering if it is related to the size of the URL and if so what possible resolution there could be.

Re: PHP session variable not being transferred

Posted: Tue Apr 01, 2008 7:51 pm
by Christopher
If you are redirecting then you need to do a session_write_close() before the redirect because both pages are in the same request. PHP will not reload an already open session.

Re: PHP session variable not being transferred

Posted: Tue Apr 01, 2008 8:27 pm
by michaelh613
arborint wrote:If you are redirecting then you need to do a session_write_close() before the redirect because both pages are in the same request. PHP will not reload an already open session.
I've never had to do this before on another page when I used

header("Location: "http://testurl.com");

I did test it and it did not resolve the problem

I do appreciate everyones attempts.

Re: PHP session variable not being transferred

Posted: Tue Apr 01, 2008 9:14 pm
by michaelh613
Problem resolved

I appreciate everyones help. When I kept noticing hardcoding worked I decided to try
$uri = trim($uri);

which resolved the problem.
Must have had some hidden whitespace when the valure is dynamicially generated.