Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Why isn't the session maintained?

session

  • Please log in to reply
2 replies to this topic

#1 acrionx

acrionx

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 11 October 2010 - 05:02 PM

I have written out a script that let's you define a session variable called "colors". Once it is defined and you close the page and then go back to it, it is suppose to remember and tell you the color you have set. But it is not doing that.

Here is my html and php code.

Here is the actual page.

When you first visit this url, you are suppose to type in a color or whatever you want to type in. When you close the window and go back to the same url, it isn't suppose to give you that text box. It is suppose to remember the $_SESSION['color'] variable and simply print that out . I can't figure out why it's not doing this. It's like a new session starts. Why isn't my preveious session variable maintained? I think it has to do with the fact that the PHP is embedded in HTML, because when I have another script that did work and that one has only PHP codes and no HTML
  • 0

#2 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 11 October 2010 - 07:04 PM

session_start() calls an HTTP header to the client, thus it must be run before any content is sent out (incliding whitespace). Place it at the top if you script, i.e.
<?php session_start();?>
Also note you output the HTML form regardless of it the session element is present or not.
  • 0

All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.


#3 acrionx

acrionx

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 12 October 2010 - 12:05 PM

Thanks Nullworm, it worked.

Here is the modified code if anyone wants to see it.
  • 0





Also tagged with one or more of these keywords: session

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