0

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; ?>
but again nothing was displayed.

Anyone got any ideas what i have done wrong?

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by decade
1

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><br>
<html>

test.php

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

Edited by Evenbit: correcting markup

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.