Reputation: 633
I'm facing the weirdest issue I've ever seen with PHP. I will try to be really exhaustive because each detail can count.
I have 3 PHP pages, and their HTML is generated using Smarty. They all call session_start()
at their top.
$_SESSION
with a unique id.To sum up :
heavy first page => second page creating and storing a PHP object into $_SESSION
=> third page, included in second page's HTML code, searching for this object and creating a preview.
The problem is, sometimes, this third page is trying to load the object in $_SESSION
and it's just not there !
Some facts :
$_SESSION
variables at the very end of the second page I can ALWAYS see the generated object in my session So it seems that the issue is located between the very end of the second page and the beginning of the third, but all of this related to the activity of the first one ! All I know is that it is linked to a fast navigation between pages.
I've tried almost everything :
session_write_close()
everywhere it's possible (at the end of my pages before/after smarty display, then at the beginning before session_start()
)exit()
at the end of my scriptssleep(1)
at the beginning of the third in case session close operation needs more timeNothing works. I have no more clues ... Maybe Smarty ? Maybe some odd PHP session behaviour named bug #4454 somewhere ?
Thanks a lot in advance for helping me with this.
Edit : piece of code after serialize()
chat
/* ===== Page2.php ===== */ /*creating object $card and setting some values ...*/ /*calling the function that gives the card preview*/ $assigns['front'] = $card->getPreviewURL(); /*other stuff ... assign $assigns to smarty ... etc*/ /* ===== Card object class ===== */ function getPreviewURL() { $_SESSION['products'][$this->getObjectId()] = serialize($this); $url = '/page3.php?s='.$this->getObjectId(); return $url; } /* ===== Page2.html ===== */ img src="{$front}" alt="toto" /* ===== Page3.php ===== */ /*getting id value and reading session*/ if(!empty($_GET['s'])) { session_write_close(); $session = new Session; if(!empty($_SESSION['products'][$_GET['s']])) { $product = unserialize($_SESSION['products'][$_GET['s']]); } else { log('$_SESSION[products]['.$_GET['s'].'] does NOT exist'); header("Status: 404 Not Found"); exit; } }
and when bug occurs, I get :
page2.php debug log : Session value : [o20aee110e0853e74da4d17c9b7ab3075]=>O:8:"Postcard":19:{s:4:"tmpl";O:16:"PostcardTemplate":20:{s:2:"id";s:3:"152";s:2:"or";i:0;s:3:"ord";s:2:"14";s:11:"description";s:0:"" ... etc
page3.php debug log : $_SESSION[products][o20aee110e0853e74da4d17c9b7ab3075] does NOT exist
Upvotes: 1
Views: 853
Reputation: 16905
Probably, the problem is, that PHP tries to unserialize your object but cannot find the class definition.
You can do one of the following two things:
serialize() the object manually before you put it into the session and unserialize() it after you loaded the class definition.
Or: Use autoloading.
Upvotes: 1