1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: PHP Sessions

Discussion in 'Web Design & Development' started by lumentec, Sep 28, 2008.

Thread Status:
Not open for further replies.
Advertisement
  1. lumentec

    lumentec Thread Starter

    Joined:
    Mar 23, 2008
    Messages:
    103
    I have a session that I start on a login.php page that stores a value called "items" taken from a MySQL Database to $_SESSION['items']. I set the value of the array on a page and it displays fine... but when I do this, it doesn't display.

    Code:
    <p id="items">
    <?php 
    echo $_SESSION['items'];
    ?>
    </p>

    Does the PHP not work inside the HTML? If so, how can I fix it?

    Does the session expire for some reason? How can I fix that?
     
  2. bob121

    bob121

    Joined:
    Sep 10, 2006
    Messages:
    207
    That seems fine,

    On the page that you are requesting that session information, do you have session_start(); on that php file at all, or included from another PHP file

    All pages which use the session information must include session_start();

    Thanks James.
     
  3. lumentec

    lumentec Thread Starter

    Joined:
    Mar 23, 2008
    Messages:
    103
    Ohhhh. Yeah. That was the problem.

    Thanks for the help. :p
     
  4. bob121

    bob121

    Joined:
    Sep 10, 2006
    Messages:
    207
    No Problem :)
     
  5. lumentec

    lumentec Thread Starter

    Joined:
    Mar 23, 2008
    Messages:
    103
    But now... I'm getting a PHP error...
    "
    Cannot send session cache limiter - headers already sent
    "

    I have no other PHP on the page... what's wrong?
     
  6. bob121

    bob121

    Joined:
    Sep 10, 2006
    Messages:
    207
    <?php session_start(); ?> must be on line one of your script.
     
  7. lumentec

    lumentec Thread Starter

    Joined:
    Mar 23, 2008
    Messages:
    103
    There we go. Finally, no more errors. :p

    Thanks for your help. :)
     
  8. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/754245

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice