Lodius2000 Posted July 10, 2008 Share Posted July 10, 2008 hi, i am integrating redirects into my already working blog cms, so when i create or edit an entry (page 1) i want my entry management page (page 2) to display the last changes made on the edit or creation page page 1 of writes a session variable then it redirects to page 2 like so <?php if ($title != $edited_title){ mysql_query("UPDATE tablename SET article_title = '$edited_title' WHERE article_id = '$id'"); $_SESSION['title'] = "Updated <strong>$title</strong> in the database.<br />\n"; } header('Location: ../page2/index.php'); ?> page2 handles the session var as like so <?php //print possible session changes due to edit/adds if (isset($_SESSION['title'])){ print $_SESSION['title']; unset($_SESSION['title']); } ?> problem is it doesnt display the contents of the session var on page 2, I have taken out the if statement to see if there is anything there and it prints fine. would there be a problem with taking off the if statement and leaving the print and unset lines if there was no session variable called title, or would php just skip those lines or what is wrong with my if statement that it doens't display correctly? o yeah and for the obligatory first response session start is on both pages at the top Link to comment https://forums.phpfreaks.com/topic/114172-session-variables-not-persisting-from-page-to-page/ Share on other sites More sharing options...
trq Posted July 10, 2008 Share Posted July 10, 2008 I don't see any calls to session_start(), it must be in each and every page you plan on using the $_SESSION array in. Link to comment https://forums.phpfreaks.com/topic/114172-session-variables-not-persisting-from-page-to-page/#findComment-587047 Share on other sites More sharing options...
Lodius2000 Posted July 10, 2008 Author Share Posted July 10, 2008 thorpe, just edited my first post to add that i do have session start in there in but you beat me heheh:) Link to comment https://forums.phpfreaks.com/topic/114172-session-variables-not-persisting-from-page-to-page/#findComment-587052 Share on other sites More sharing options...
PFMaBiSmAd Posted July 10, 2008 Share Posted July 10, 2008 A session_start() will only start or resume a session if no content is output to the browser before the session_start(). Add the following two lines after your first opening <?php tag on both pages - ini_set ("display_errors", "1"); error_reporting(E_ALL); Link to comment https://forums.phpfreaks.com/topic/114172-session-variables-not-persisting-from-page-to-page/#findComment-587056 Share on other sites More sharing options...
Lodius2000 Posted July 10, 2008 Author Share Posted July 10, 2008 PFMaBiSmAd ive got error reporting on, like i said the guts of the script work, it posts and writes the session variables, i am taking out the part on page 1 where after clicked post, it used to tell me the changes made and provide a link back to the management page (page 2) now i am doing a redirect so the 'changes made statements' are put in to the session array and then page 1 redirects to page 2. on page 2, the session variables are called only if they exist and printed and then unset, so they are blank for the next time i need to fill them with more 'changes made statements'. like i said, if i take the if() off, print $_SESSION['title'] prints "Updated <strong>$title</strong> in the database.<br />\n" but with the if() on there it does not i havent used isset() very much and dont know if i am using it correctly or if that is even the problem Link to comment https://forums.phpfreaks.com/topic/114172-session-variables-not-persisting-from-page-to-page/#findComment-587071 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.