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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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  :-\

 

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.