Problem Using Session Variables

Hi,

I’m a php newbie and using a php form hosted on godaddy. And I can’t seem to get session variables to work. Here is my code:

Page 1:

session_start(); // start up your PHP session!
session_regenerate_id(true);

$_SESSION[‘send_to’] = $to;
$_SESSION[‘send_subject’] = $subject;
$_SESSION[‘send_body’] = $body;

header( “Location: http://somesite.com/thankyou.php”);
session_write_close();

Page 2:

session_start();

$to = $_SESSION[‘send_to’];
$subject = $_SESSION[‘send_subject’];
$body = $_SESSION[‘send_body’];

$mail = mail($to, $subject, $body);

In response I get the following error message for each of my session variables: “Notice: Undefined index: send_to”

Please help! I’ve been searching the forums for help but I haven’t found anything useful to me yet…

First of all sorry about my english.

the function session_regenerate_id(true); are not necessary, but isn’t wrong.
the function session_write_close() are not necessary, but must be before header(Location) because header(Location) blocks execution of the script. There is no necessary because always execute this at the end of the scripts, this functions will be used to save data before change session.

One requisite to use session are that all pages were at the same server.
If all pages are at the same server, we have 2 posibilities :

All page are at same domains

Page 1:

[php]
session_start(); // start up your PHP session!
$_SESSION[‘send_to’] = $to;
$_SESSION[‘send_subject’] = $subject;
$_SESSION[‘send_body’] = $body;

  header( "Location: thankyou.php"); // You can use relative or absolute url

[/php]
Page 2:
[php]
session_start();
$to = $_SESSION[‘send_to’];
$subject = $_SESSION[‘send_subject’];
$body = $_SESSION[‘send_body’];

   $mail = mail($to, $subject, $body);

[/php]

Or pages are at diferent domains

Page 1:

[php]
session_start(); // start up your PHP session!
$id = session_id();
$_SESSION[‘send_to’] = $to;
$_SESSION[‘send_subject’] = $subject;
$_SESSION[‘send_body’] = $body;

  header( "Location: http://somedomain.com/thankyou.php?idSession=$id"); // You can use relative or absolute url

[/php]
Page 2:
[php]
if($_GET[‘idSession’]){
session_id($_GET[‘idSession’]);
}
session_start();
$to = $_SESSION[‘send_to’];
$subject = $_SESSION[‘send_subject’];
$body = $_SESSION[‘send_body’];

   $mail = mail($to, $subject, $body);

[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service