Jump to content

[SOLVED] Problem assigning variables to a session?


Solarpitch

Recommended Posts

Hey Guys,

 

I had a post on this the other day in relation to assigning a variable to a session, just when I thought it was sorted... something went out of place.

 

If you look at the below code, the variables seem to assign to the sessions fine when the "header(locat..." is commented out. However, when I put the header location.... in the script, the sessions wont take the values of the variables... its a little strange.

 


step1.php...

<?php

ob_start();
session_start();

$process = isset($_POST['process']) ? $_POST['process'] : '';

if ($process != "execute")
{
//not being submitted...
}
else
{	

$firstname = $_POST['firstname'];
$_SESSION['firstname'] = $firstname;

$lastname = $_POST['lastname'];
$_SESSION['lastname'] = $lastname;


header("Location: step2.php"); // The code works when this is commented out. 
ob_flush();


}

?>

Note that step 2 page has excatly the same code as above, except it has a header location pointing to step 3 and so on. So it seems to work when the page doesnt get directed to step2.php after the form has been submitted.

Actually... that works but I get the message...

 


Warning: Cannot modify header information - headers already sent by (output started at D:\hshome\account\tep1.php:36) in D:\hshome\account\step1.php on line 37

Line 37

ob_flush();
header("Location:step2.php"); <---

Try this:

 

session_write_close();
header('Location: http://mysite.com/somepage.php');
exit(0);

 

The session might not be complete before the next page tries to read it. If this doesn't work I have other suggestions to as this has happened to me before  :-\

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.