SitePoint Sponsor

User Tag List

Page 1 of 3 123 LastLast
Results 1 to 25 of 54
  1. #1
    SitePoint Evangelist achintya's Avatar
    Join Date
    Apr 2005
    Location
    Chandannagar(India)
    Posts
    459
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Post Session not working

    Hi,
    In my code, whenever I am trying to access a session variable created in a page(say page1) in another page(say page2), it is lost. In both the pages,I have explicitly started session though. Can someone tell me why so happening? Thanks in advance.
    Last edited by achintya; Apr 2, 2010 at 02:42. Reason: Spelling mistake

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Post your code please

  3. #3
    SitePoint Evangelist achintya's Avatar
    Join Date
    Apr 2005
    Location
    Chandannagar(India)
    Posts
    459
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Page1
    PHP Code:
    session_start();
     
    ob_start();
     
    $_SESSION['value1'] = 'testing';
     echo 
    $_SESSION['value1']; 
    Page2
    PHP Code:
    session_start();
     
    ob_start();
     
    //$_SESSION['value1'] = 'testing';
     
    echo $_SESSION['value1']; 

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    Okay your session is working fine. You're Buffering your output but not...outputing it. Flush the buffer (ob_end_flush()) and see if you get what you need.

    Why are you ob_start'ing, anyway?

  5. #5
    SitePoint Evangelist achintya's Avatar
    Join Date
    Apr 2005
    Location
    Chandannagar(India)
    Posts
    459
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Lion,
    Thanks for your reply. I have done what you said...but it doesn't seems to work. Thanks again.

  6. #6
    SitePoint Evangelist achintya's Avatar
    Join Date
    Apr 2005
    Location
    Chandannagar(India)
    Posts
    459
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Does anyone has any idea about this? Thanks Again.

  7. #7
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,175
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)
    I suspect it's most likely the output buffering messing it up. If there's any way to avoid using it, don't. It may mean you have to put a little more thought into your code's logic, but IMHO it wil be worth the effort.

    Anyway, I doubt if you're using IE6, but if you are try:
    PHP Code:
    <?php
    session_start
    ();
    header("Cache-control: private"); //IE 6 Fix

  8. #8
    SitePoint Evangelist achintya's Avatar
    Join Date
    Apr 2005
    Location
    Chandannagar(India)
    Posts
    459
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks Mittineague..I have tried yours but doesn't seem to work.

  9. #9
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,029
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    achintya, in your phpinfo() what are the settings in the sessions section?
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  10. #10
    SitePoint Evangelist achintya's Avatar
    Join Date
    Apr 2005
    Location
    Chandannagar(India)
    Posts
    459
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks SpacePhoenix. Following are the settings:

    Code:
    session.auto_start	Off	Off
    session.bug_compat_42	Off	Off
    session.bug_compat_warn	On	On
    session.cache_expire	180	180
    session.cache_limiter	nocache	nocache
    session.cookie_domain	no value	no value
    session.cookie_httponly	Off	Off
    session.cookie_lifetime	0	0
    session.cookie_path	/	/
    session.cookie_secure	Off	Off
    session.entropy_file	no value	no value
    session.entropy_length	0	0
    session.gc_divisor	1000	1000
    session.gc_maxlifetime	1440	1440
    session.gc_probability	1	1
    session.hash_bits_per_character	5	5
    session.hash_function	0	0
    session.name	PHPSESSID	PHPSESSID
    session.referer_check	no value	no value
    session.save_handler	files	files
    session.save_path	/var/www/vhosts/mydomain.com/httpdocs/tmp/	/var/lib/php/session
    session.serialize_handler	php	php
    session.use_cookies	On	On
    session.use_only_cookies	Off	Off
    session.use_trans_sid	0	0
    As far as the save_path is concerned, i have changed the first one using ini_set function. Thanks again.

  11. #11
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,029
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by achintya View Post
    As far as the save_path is concerned, i have changed the first one using ini_set function. Thanks again.
    Did you change the save_path before or after the problem with sessions started to occur?
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  12. #12
    SitePoint Evangelist achintya's Avatar
    Join Date
    Apr 2005
    Location
    Chandannagar(India)
    Posts
    459
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I have changed the save_path after the issue started. Thanks again.

  13. #13
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    It seems to be correct...Create a new page. Put this code in it. Run it in your browser, and tell me what it says?

    PHP Code:
    <?php
    session_start
    ();
    echo 
    session_id();
    ?>

  14. #14
    SitePoint Evangelist achintya's Avatar
    Join Date
    Apr 2005
    Location
    Chandannagar(India)
    Posts
    459
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    It says something like this...
    sjgf6cfrr8rqjl0oea3366qpd6

  15. #15
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,175
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)
    That looks like it could be a session hash. My phpinfo() has a few differences from yours
    yours
    Code:
    ...
    session.bug_compat_42	Off	Off
    ...
    session.gc_divisor	1000	1000
    ...
    session.hash_bits_per_character	5	5
    ...
    session.save_path	/var/www/vhosts/mydomain.com/httpdocs/tmp/	/var/lib/php/session
    ...
    mine
    Code:
    ...
    session.bug_compat_42	On	On
    ...
    session.gc_divisor	100	100
    ...
    session.hash_bits_per_character	4	4
    ...
    session.save_path	\xampplite\tmp	\xampplite\tmp
    ...
    TBH I don't know what the importance of the first 3 are off the top of my head, I'd need to look into them. But the save_path is significant because I have Windows OS that uses back slashes.

    Again, why are you using output buffering? If it's only to avoid "already sent" errors try rewriting your code.

  16. #16
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    Yeah, sounds like the session ID is being created fine...

    You're not doing something silly like destroying the session at the end of page 1, are you? I think we're missing seeing something in your code because you have not posted most/all of it.

  17. #17
    SitePoint Evangelist achintya's Avatar
    Join Date
    Apr 2005
    Location
    Chandannagar(India)
    Posts
    459
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    No not at all...I have posted all of it.

  18. #18
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    If you echo session_id() on page2, does it give you the same answer as page1?

  19. #19
    SitePoint Evangelist achintya's Avatar
    Join Date
    Apr 2005
    Location
    Chandannagar(India)
    Posts
    459
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    No it displays a different value from first page..

  20. #20
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    So the problem is that the session isnt retaining.

    1) Page1 is on the same website as page2?
    2) Have you enabled cookies on your browser?

  21. #21
    SitePoint Evangelist achintya's Avatar
    Join Date
    Apr 2005
    Location
    Chandannagar(India)
    Posts
    459
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    My replies are the below

    1)Yes same website.
    2)I am using Firefox version 3.5.9 - Do I need to enable cookies manually in this browser?

  22. #22
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    No it should be enabled automatically (and really shouldnt matter anyway, really).

    Unless somewhere in your script you're destroying the session, or page2 is in a directory at a higher level than page1, i cant explain this other than 'php is misconfigured'... so at this point i'm going to call on the more skilled to come up with an answer i havent thought of.

  23. #23
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,175
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by achintya View Post
    No not at all...I have posted all of it.
    Quote Originally Posted by achintya View Post
    Page1
    PHP Code:
    session_start();
     
    ob_start();
     
    $_SESSION['value1'] = 'testing';
     echo 
    $_SESSION['value1']; 
    Page2
    PHP Code:
    session_start();
     
    ob_start();
     
    //$_SESSION['value1'] = 'testing';
     
    echo $_SESSION['value1']; 
    This is what you're testing with and it's all of it?
    As mentioned before, you are starting OB but not flushing. Try it without the OB

  24. #24
    SitePoint Evangelist achintya's Avatar
    Join Date
    Apr 2005
    Location
    Chandannagar(India)
    Posts
    459
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I have tested without OB but it doesn't make any difference. Many thanks.

  25. #25
    SitePoint Evangelist achintya's Avatar
    Join Date
    Apr 2005
    Location
    Chandannagar(India)
    Posts
    459
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Anyone has any idea? Thanks anyway...


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
  •