Jump to content

[SOLVED] PHP Session variable not being transferred


michaelh613

Recommended Posts

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 

 

 

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.