Page 1 of 1

Passing sessions [RESOLVED]

Posted: Fri Jan 06, 2006 6:23 am
by robokoder
I have a script which is part of a form page. All it does is set a sessin, and the idea is that when the the form is submitted the php script checks the session.

However, an isset check always returns false for the variable- what have I done wrong?!

Please help!

P.S. The php script that makes the session is hiding as an img src, the actual form page is .html and has no php on it.

If you need any code, I can post it

Posted: Fri Jan 06, 2006 7:32 am
by Jenk
post code pls.

sessions are very easily managed in PHP as they are automanaged by the php backend.

However, when you intend to use a session variable, you must use the $_SESSION superglobal, normal global variables do not pass between requests.

Posted: Fri Jan 06, 2006 8:09 am
by Jim
You also need to ensure you've used session_start() somewhere on the page before your session is created! :)

Posted: Fri Jan 06, 2006 8:40 am
by robokoder
I gave up and used cookies :(

Anyways, it works great and I'd like to say a great big thank you to some users on this forum who helped me out!

The site is at http://encode.fusionnx.com, and forthe 24 hoours or so I'll be opening it to the public- user & pass is 'tester'.

Let me know what you think through PMs, email and replies (I have posted a seperate thread in the chat forum)

Posted: Fri Jan 06, 2006 8:56 am
by Jenk
dude.. seriously, it's as easy as using cookies.. infact, I'd say easier depending on your situation.

page1.php:

Code: Select all

<?php
session_start();

$_SESSION['var'] = true;

?>
page2.php:

Code: Select all

<?php
session_start();

if ((isset($_SESSION['var'])) && ($_SESSION['var'] === true)) {
    echo "Session variable 'var' is boolean and equals true!";
}

?>
But don't confuse sessions with cookies.. if you close the browser, the session will be destroyed. Cookies only get destroyed when they expire.