Posted By

Wardy on 10/22/08


php session header location redirect

Versions (?)

Who likes this?

2 people have marked this snippet as a favorite


Save session value - then header redirect

 / Published in: PHP


The problem is some times the redirect may kick you off to the next page before all the session variables have been saved. The true solution to lost session vars on redirect is to simply call sessionwriteclose(); before setting the redirect header. This will insure that php finishes writing the session info before page redirect gets underway.

  1. <?
  2. $_SESSION['forward'] = "This session data will not be lost!";
  4. header('Location: nextpage.php');
  5. ?>

Report this snippet  

You need to login to post a comment.