www.webdeveloper.com
Page 2 of 2 FirstFirst 12
Results 16 to 16 of 16

Thread: Page starts new session

  1. #16
    Join Date
    Aug 2012
    Posts
    15
    Fixed. it. Damn it. It was easy, but not obvious, which I am learning seems to be pretty standard, especially for beginners like me.

    In the end it all I had to do was put the session_start() command at the very beginning. Before anything. Including the DOCTYPE line. W3Schools.com says to put it before the <html> line, but it has to go even higher.

    Having pretty much given up on $_SESSION I spent the day studying cookies for PHP and had figured out what I'd need to do if I was going to go that route. Basically, create the cookies in php, manipulate the data in php, then use JavaScript's window.onload to save the new values to the client computer. A bit awkward, but not horrible. I just had to use some "if {! isset($_COOKIE..." code to make sure I didn't overwrite existing cookies.

    I thought it was weird that the code to create the cookies had to come first. What idiot puts code before the start of the program, was what I was thinking, but that was the only thing that worked, and yes, I could stick my function CreateNewCookie in there, too.

    So that sent me back to php.net to read up more on session_start and there were many accounts of problems like what I was having, with solutions. One was
    Quote Originally Posted by alakys
    Sorry for the noob comment but for those having the error :

    Warning: session_start(): Cannot send session cache limiter - headers already sent ...

    And before trying all the solutions added by the experts, simply ensure to have your php code before even the DOCTYPE tag like this (and not between the doctype and html tags as I was doing):

    <?php session_start(); ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Test Page</title>
    </head>

    <body>
    etc ....

    It might sound funny but I am sure this post will save time to some others noobs like me ... !
    Many thanks, alakys. I suffered plenty before I found your post and tried it so I didn't save much time, but damn I was getting headaches, cramps, a really sore butt, and was close to giving up, and I would have hated myself forever for that.

    I'll put it to bed tonight, get another late dinner, and will turn up my amp and bang on my guitar until I get some of this out of my system. It's 9:30 PM on a Saturday. The neighbors will understand.

    Mike

    P.S. How the hell did I ever get this to work at all? For the past week or so SESSIONS was working for me, on this one machine.
    Last edited by m610; 08-18-2012 at 11:27 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles