Jump to content

session variables not persisting from page to page


Lodius2000

Recommended Posts

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

 

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.