Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Session variables not registering

session session variable registering

  • Please log in to reply
2 replies to this topic

#1 avingard

avingard

    CC Lurker

  • Just Joined
  • Pip
  • 8 posts

Posted 10 June 2008 - 06:52 AM

I'm registering session varibles using $_SESSION[] and they aren't staying registered. I know that sounds weird, but I've tried and when I echo the session variable on the first page (before redirecting using header('location: page.php')) it shows up fine; however, after the redirect, the session variable always fails isset().

What am I missing? Anyone know what could cause this?
  • 0

#2 veridicus

veridicus

    CC Lurker

  • New Member
  • Pip
  • 5 posts

Posted 11 June 2008 - 06:48 AM

Questions: Are you tracking sessions using cookies or the URL? Did you check to see if the sessions are being properly written to disk (or database)? Do you call session_start at the very beginning of your scripts before any output?
  • 0

#3 Whitey

Whitey

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 259 posts

Posted 11 June 2008 - 01:42 PM

Well first you must have session_start() on all the page's you are using the session variable on. And it must be at the top (or above the head tags).

And this is how i register a session..

session_start();
session_register(username_taken);
$_SESSION['username_taken'] = "<center><font color='red' size='1'>The Username You Chose Is Already In Use</font></center>";
header("location:register.php");


Then on the page that you are viewing the session you would do this

session_start();
if(session_is_registered(username_taken))
{
echo ($_SESSION['username_taken']);
session_unregister(username_taken);
session_destroy();
}

  • 0





Also tagged with one or more of these keywords: session, session variable, registering

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download