michaelh613 Posted April 2, 2008 Share Posted April 2, 2008 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. $_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 <?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 The issue must be related because I am moving a URL. When I change the equidatauri to have something other than a url it works correctly. I appreciate any help you can give Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 2, 2008 Share Posted April 2, 2008 Your posted code appears to have a newline before the first opening <?php tag. This will prevent the session from starting. Just because you can echo a variable called $_SESSION... on a page, does not necessarily mean that it is an actual session variable. Add the following two lines after your first opening <?php tag to get php to help you - ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment Share on other sites More sharing options...
michaelh613 Posted April 2, 2008 Author Share Posted April 2, 2008 Your posted code appears to have a newline before the first opening <?php tag. This will prevent the session from starting. Just because you can echo a variable called $_SESSION... on a page, does not necessarily mean that it is an actual session variable. Add the following two lines after your first opening <?php tag to get php to help you - ini_set ("display_errors", "1"); error_reporting(E_ALL); There is no newline. Just just put one accidentally in in the code when I created it here. Session variables are set because other session variable are coming over. Just tested hardcoding the value $_SESSION['equidatauri'] = "http://test.com"; and that transferred as a session variable successfully. I have used the echo command to verify $uri is properly being populated but it appears to be somehow related to that variable. Quote Link to comment Share on other sites More sharing options...
michaelh613 Posted April 2, 2008 Author Share Posted April 2, 2008 Is there a size limit on the variable that is being moved over. My real URL is very large. I just put tested it again using the same variable name but setting it to http://test.com and it worked. So the problem appears to be with the actual variable I am using. Again it populates on my first page when I echo it but does not move to the new page. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 2, 2008 Share Posted April 2, 2008 If only one session variable is getting overwritten, you probably have register globals on and have a program/post/get/cookie variable with the same name as the session variable. Use unique variable names for program/session/post/get/cookie when register globals are on to prevent session variables from being set from outside yours script. If that does not solve the problem, then your code contains logic that is overwriting the session variable. You would need to post your actual code to get specific help with it. Quote Link to comment Share on other sites More sharing options...
michaelh613 Posted April 2, 2008 Author Share Posted April 2, 2008 The variable works OK when it is set to http://test.com. But with my large one it gives a problem. Thats why I am thinking there is some size limitation? Quote Link to comment Share on other sites More sharing options...
teng84 Posted April 2, 2008 Share Posted April 2, 2008 are you sure you have a session start on each page? Quote Link to comment Share on other sites More sharing options...
michaelh613 Posted April 2, 2008 Author Share Posted April 2, 2008 Yes I have sessions start page 1 <? session_start(); //ob_start(); set_time_limit(120); $post = array_merge($_SESSION['posted_vars'],$_SESSION['posted_vars2']); page 2 <?php session_start(); ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment Share on other sites More sharing options...
teng84 Posted April 2, 2008 Share Posted April 2, 2008 can you show me how you set and echo those var form page to page ? Quote Link to comment Share on other sites More sharing options...
michaelh613 Posted April 2, 2008 Author Share Posted April 2, 2008 can you show me how you set and echo those var form page to page ? Sure seen even stranger stuff when I hard code. I've hardcoded the long url and it works. Yet when I echo dynamically creating it it shows up correctly on the first page but not on the 2nd page 1 //$_SESSION['equidatauri'] = $uri; This is setting it dynmacally //echo "the uri is $uri <br>"; I've tested the value $uri here $_SESSION['equidatauri'] = "https://www.testurl.net/ConsumerInterface/ExternalV2/Validate.asp?session=6ZM7Fv0ZUA2%2B%2BPvXaDrelXLI%2B34WHXsNds8gP60%2Bgmq6UBZ9Ju17okjLq67fN6NvukzrdzQrvDyJ1AUYsA9MUq21fiUJCitVR04%3D //"; //echo "<br>The session url in thankyou.php to go to is " .$_SESSION['equidatauri']."<br>"; I've tested the session url and it works either way here //echo "about to redirect header <br>"; $_SESSION['condition'] = $condition; //echo "<br>The session url in thankyou.php to go to is " .$_SESSION['equidatauri']."<br>"; //echo "about to redirect header <br>"; //session_write_close(); header("Location: http://page2/secure/thanks.php"); page 2 looks like <?php session_start(); //ini_set ("display_errors", "1"); //error_reporting(E_ALL); //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']; echo "<br>The variable url in thanks.php to go to is $equidatauri <br>"; ?> all my session variables are passed except for $_SESSION['equidatauri'] when it is dynamically generated. Quote Link to comment Share on other sites More sharing options...
teng84 Posted April 2, 2008 Share Posted April 2, 2008 not sure why you need to use complete path header("Location: http://page2/secure/thanks.php"); just header("Location: thanks.php"); where is this thanks.php? Quote Link to comment Share on other sites More sharing options...
michaelh613 Posted April 2, 2008 Author Share Posted April 2, 2008 The actual URL is behind a password protected site. We don't expose our developement server to the public. I don't see how using absolute or relative URL's should matter here. Indeed absolute ensures no mistakes in the location. Quote Link to comment Share on other sites More sharing options...
michaelh613 Posted April 2, 2008 Author Share Posted April 2, 2008 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.