CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2003
    Location
    kathmandu, nepal
    Posts
    1,570

    $_SESSION not working PHP

    Hello all,

    The problem is that my session variable dies in another page ...when I link from one page to another. I can access session variable in a.php but a.php -> has a link that takes you to b.php ...now in b.php I can't access that session variable

    Code:
    if(isset($_SESSION['username']))
    { 
        print("What you want if the session var is set");
    }
    else 
    { 
        print("What you want if the sessions variable is not set");
    }
    It says username is not set ...

    whereas I can access and has the correct value in a.php

    Please help.

    Thanks
    If there is no love sun won't shine

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: $_SESSION not working PHP

    Are you sure you are starting the session at the top of every page that is attempting to access the session? Have you used an id or name in one page and not the other?
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Apr 2003
    Location
    kathmandu, nepal
    Posts
    1,570

    Re: $_SESSION not working PHP

    Yes I am starting the session on each page.

    I am using the following as the first line on each page
    Code:
    session_start()
    I am not sure I understand what you mean by id or name in one and not other. Could you please explain a bit more?

    Thanks
    If there is no love sun won't shine

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: $_SESSION not working PHP

    Without supplying a session id or name before creating the session, every person who views your page will have/control the same session.

    If you plan to work with logins, you will want something more along the lines of...
    PHP Code:
    session_id('UNIQUE_ID');
    session_start(); 
    Or...
    PHP Code:
    session_name('NAME'); // this automatically handles the different ids
    session_start(); 
    As to your problem...how about your session configuration in your php.ini file? What is their lifetime? The best way to check would be to use phpinfo() to output your configuration.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured