954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

PHP sessions

Hi, I am developing a CMS based website which also has a flash gallery, the gallery accepts only xml data as input so i am using info from a database to output the required xml using php.

I am setting the page that is currently being viewed using a session, i had then planned on using this session in the sql query to return only images that have been uploaded for that particualr page.

My problem is the session does not seem to be available to use in the xml page. I have used echo to check the value is stored on the page where the gallery is displayed, but on the page that outputs the xml there is nothing.

I then decided to create a test page which i used <?php echo $_SESSION['gallery']; ?>
but again nothing was displayed.

Anyone got any ideas what i have done wrong?

pjh1985
Light Poster
28 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

Your test page must also have 'session_start()' at the top before any output. For compatibility with old versions of IE, you'll also want to add the P3P header.

index.php

<?php header('P3P CP="CAO PSA OUR"');
session_start();
$_SESSION['gallery'] = 42;
?>
<!DOCTYPE html>
<html>
<h1>Setting cookie!</h1>
<a href="/test.php">test</a>
<html>


test.php

<?php header('P3P CP="CAO PSA OUR"');
session_start();
$value = $_SESSION['gallery'];
?>
<!DOCTYPE html>
<html>
<h1>Getting cookie!</h1>
<? echo($value); ?>

<html>
Evenbit
Junior Poster
140 posts since Mar 2005
Reputation Points: 99
Solved Threads: 5
 

Ahh ok didnt know you had to start the session again. Thanks very much

pjh1985
Light Poster
28 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

always put session_start(); at the top of your session

decade
Junior Poster in Training
62 posts since Jun 2011
Reputation Points: 12
Solved Threads: 14
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You