www.webdeveloper.com
Results 1 to 5 of 5

Thread: session variables problem

  1. #1
    Join Date
    Nov 2010
    Posts
    49

    session variables problem

    So I've used sessions a heap before but they have decided they don't like me anymore and are not working.. I cannot for the life of me work out why and it's driving me crazy..
    I have a page that sets a login name in $_SESSION['login_name'] and when I try to use that on another page, say to echo it, it is not there (not on any of my pages).. Then I go back to the login page (the one that set it) and find that it won't echo there anymore either. So it's kind of like a session that only lives while I'm on that one page...
    As a test I created a real simple page to set $_SESSION['test']. I echo'ed that on another page successfully but it wont echo on the login page.. it's like I have a session destroy hiding in the login page.. only I don't.
    And yes, I do have session_start(); at the top of my php.

    Any suggestions before I start smashing my head on the wall?

    cheers,

    bob

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,933
    Anything in the PHP error logs about session_start() not working?

    Also, you can get hit by a problem with the session ID cookie if you access some pages with the "www." sub-domain in the URL and some without it. You can avoid that issue if you set the session.cookie_domain setting to ".example.com" (note the leading dot), which will ensure the cookie is exchanged regardless of whether the page is accesses via "http://example.com" or "http://www.example.com".
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Nov 2010
    Posts
    49
    thanks dude, the www part is the issue.. to use
    ini_set('session.cookie_domain', '.domain.com');
    I would have that before session_start();
    correct?
    (that doesn't seem to fix it..)

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,933
    You can use the session_set_cookie_params() function, but you need to do it on each and every page before the session_start() call.
    PHP Code:
    <?php
    session_set_cookie_params
    (0'/''.yourdomain.com');
    session_start();
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Nov 2010
    Posts
    49
    thanks NogDog, you are seriously a champion mate

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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