SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Sessions problem

  1. #1
    SitePoint Wizard bronze trophy bigalreturns's Avatar
    Join Date
    Mar 2006
    Location
    The Wirral, England
    Posts
    1,293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sessions problem

    I'm having problems with errors saying that session cookies cannot be sent, as header data has already been sent, and cant figure out why! I have the session start command as the first line of php, and it is enclosed in the head tags. The error message is...

    Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/abdpqj/public_html/login.php:3) in /home/abdpqj/public_html/login.php on line 4

    The code I am using is...

    Code:
    <html>
    <head>
    <?
    session_start();
    $_SESSION['logged']="0";
    ?>
    </head>
    <body>
    <form name="login" action="member.php" method="post">
    Username:  <input name="name" type="text" id="name"><br>
    Password:  <input name="pass" type="password" id="pass"><br>
    <input type="submit" name="submit" value="submit">
    </form>
    </body>
    </html>
    "The proper function of man is to live - not to exist."
    Get a Free TomTom


  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,513
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have the session start command as the first line of php, and it is enclosed in the head tags.
    It should be before any html.

  3. #3
    SitePoint Wizard bronze trophy bigalreturns's Avatar
    Join Date
    Mar 2006
    Location
    The Wirral, England
    Posts
    1,293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks, nice and simple one one to fix! But... how long does a session stay open for? ie are its variable still accessible when the user navigates to a new page on my site?
    My problem is that when they log in (using the code in my first post), they are taken to a profile page, which checks the password then displays the details. if the password is valid it then sets the variable $_SESSION['uname'] to the name they entered. However, when they then navigate to an edit profile page, and I try to retrieve the $_SESSION['uname'] variable, it comes back as "". Whats going wrong here?
    "The proper function of man is to live - not to exist."
    Get a Free TomTom


  4. #4
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're sure you are starting each page with session_start(); right?

  5. #5
    SitePoint Wizard bronze trophy bigalreturns's Avatar
    Join Date
    Mar 2006
    Location
    The Wirral, England
    Posts
    1,293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    errrrmm, suuuure yeah. thats a no btw, didnt pick up from any tutorials that you had to!! thanks for the advice
    "The proper function of man is to live - not to exist."
    Get a Free TomTom


Bookmarks

Posting Permissions

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