I’m sure this must be pretty straightforward, but I’m not that familiar with sessions yet.
I am basically trying to pass a session from one age to the next.
On the first page I have this:
<?php
@session_start();
if ("" == "") {
$_SESSION["Lodge_GSG_URL"] = "".$row_rs_Lodge['GSG_URL'] ."";
}
?>
And on that page I can echo the session correctly using:
<?php echo $_SESSION['Lodge_GSG_URL']; ?>
On the second page, I have this, but it doesn’t display anything:
<?php
session_start();
echo $_SESSION['Lodge_GSG_URL'];
?>
If anyone could help out that would be much appreciated.
Thank you!
On the second page, try this.
<?PHP
session_start();
echo '<pre>';
var_dump( $_SESSION );
echo '</pre>';
Rubble
August 17, 2014, 1:40pm
3
Going a bit off track your code looks a bit of a mess to me, what is the if supposed to do as it will always be true?
Why not try something simple like:
<?php
@session_start();
$_SESSION["Lodge_GSG_URL"] = $row_rs_Lodge['GSG_URL'] ;
?>
Then when you are sure it is working expand it.
Just noticed that session_start() should be at the very beginning of the page and should never be prefixed with @.
Also the $row_rs_lodge variable cannot possibly exist.
Thanks. Is that on the first or second page?
The code on the first page works as I would expect.
session_start(); should be first on both pages. I made this mistake when first using sessions and could not understand why the scripts were not working.
It helps if you set set error_reporting(-1); and ini_set(‘display_errors’,true);
Thanks - it looks like its working now.
So the last part of this is the bit where I actually want to use the value in the session for a redirect link in some PHP code in a page header.
The code is:
“successRedirect” => “…/africa/session_variable_here/”,
I can’t quite get the syntax right, but think it should be something like this?
“successRedirect” => “…/africa/.”$_SESSION[‘Lodge_GSG_URL’].“/”,
That was nearly correct - its working now with:
“successRedirect” => “…/africa/”.$_SESSION[“Lodge_GSG_URL”].“/”,