0

So I'm validating this form, when there are no errors it redirects with a header to a confirmation page. I want to get all the $_post data and put them into session variables so I can pass the data onto the confirmation page. However I get the error 'Cannot modify header information - headers already sent by', I assume this is happening because of a conflict with 'session_start'

 if  ($errors == 0) { 
     session_start();
     header('Location:../confirmation.php');
 }
 else {
     header('Location:../order.php');
 }

What do?

iatboy
  • 1,295
  • 1
  • 12
  • 19
user1375823
  • 95
  • 1
  • 12
  • Even after getting rid of the error, the session variables are empty. – user1375823 Nov 29 '14 at 04:44
  • 1
    I think `session_start();` needs to be the first line of your page. So place it outside if condition this might solve your problem. – Indrasinh Bihola Nov 29 '14 at 04:48
  • Doesn't matter, after moving stuff all around I managed to make something work. – user1375823 Nov 29 '14 at 04:49
  • Did you set the session variables before the redirection? The session variables are not set by themselves. `$_SESSION['_POST'] = $_POST;` – Cheery Nov 29 '14 at 04:49
  • 1
    @IndrasinhBihola `needs to be the first line of your page` it can be anywhere, just before the actual output to the browser. – Cheery Nov 29 '14 at 04:50

0 Answers0