Passing sessions [RESOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
robokoder
Forum Newbie
Posts: 13
Joined: Wed Jan 04, 2006 9:23 am
Location: London, UK

Passing sessions [RESOLVED]

Post 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
Last edited by robokoder on Fri Jan 06, 2006 8:40 am, edited 1 time in total.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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.
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Post by Jim »

You also need to ensure you've used session_start() somewhere on the page before your session is created! :)
robokoder
Forum Newbie
Posts: 13
Joined: Wed Jan 04, 2006 9:23 am
Location: London, UK

Post 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)
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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.
Post Reply