Session Problem

Discussion in 'PHP' started by blogatom, Jul 14, 2008.

  1. #1
    Hi
    I am having problem with sessions in my site , the session data gets lost randomly . My site is on a shared hosting so i can't edit php.ini ( i am on hostgator )
    Please help me :(
     
    blogatom, Jul 14, 2008 IP
  2. Mozzart

    Mozzart Peon

    Messages:
    189
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Is this a custom code or something? else post the bits and behavior of what's happening
     
    Mozzart, Jul 14, 2008 IP
  3. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #3
    Too vague, I can only guess what can be happening...

    They may lose their session cookie or something obscure, try adding SID to the end of all links.

    Dan
     
    Danltn, Jul 14, 2008 IP
  4. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #4
    This not a secure way at all. But to debug you can try this.
     
    mwasif, Jul 14, 2008 IP
  5. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #5
    I would've assumed he had locked sessions to an IP...

    Obviously it's a risk if he hasn't, and the user goes posting their session link on forums etc.

    Dan
     
    Danltn, Jul 14, 2008 IP
  6. blogatom

    blogatom Peon

    Messages:
    264
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Hi
    After lot of testing i think i have identified the bug but i don't know how to resolve it .
    The problem occurs when i login the site and click a link ( an external link which opens in new TAB ) from my account and when i come back to the current TAB ( my site ) the session data is lost and i am redirected to the login page , this happens in both IE and firefox
    and i am using session_start(); on every page but still i get this problem :(
     
    blogatom, Jul 15, 2008 IP
  7. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #7
    You will definitely loose session when your exit page (url) before going to some other site is different than returning url. e.g. If you were browsing page www.yourdomain.com/somepage.php and went to some external site. And after some time you come to the same page or different page but without www i.e. yourdomain.com/otherpage.php.

    The reason behind is that the session was created for www.yourdomain.com, but you came back on yourdomain.com. If you use www with the url, your problem will be solved.

    You can solve this problem by setting session cookie domain using session_set_cookie_params().
     
    mwasif, Jul 16, 2008 IP
  8. blogatom

    blogatom Peon

    Messages:
    264
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Hi , thanks for the reply but the problem is not with using "www" or not ( my site's url remain the same as it was before either www or without it ) . the problem occurs when i click on a link in my account to some other site which opens in new tab and when i come back to my current tab , the session data is lost .








     
    blogatom, Jul 16, 2008 IP
  9. sastro

    sastro Well-Known Member

    Messages:
    214
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #9
    It is a strange problem. I have domains hosted on hostgator and got no problem with session. You should ask your friend to browse your web from his computer.
     
    sastro, Jul 16, 2008 IP
  10. blogatom

    blogatom Peon

    Messages:
    264
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #10
    :) Problem solved :)
    after a lot of googling about my problem i found this
    The session variable is still lost when navigating even if I change $setting or $_SESSION['setting']. 
    
    If you assign a session subscript/key to the same name as a variable, the session variable will be volatile and lost upon navigating.
    
    For example, if passing a setting that you want in $_SESSION, don't do this:
    
    <?
    $setting = $_REQUEST['setting'];
    if (!empty($setting))
       $_SESSION['setting'] = $setting;
    ?>
    
    Instead, rename $setting or $_SESSION['setting']. 
    Code (markup):

    I was also having the same problem , after renaming some of my variables my problem got solved :D:D
    BTW thanks for your inputs
     
    blogatom, Jul 17, 2008 IP
  11. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #11
    It means register_globals is on in your php.ini.
     
    mwasif, Aug 1, 2008 IP
  12. yleiko

    yleiko Peon

    Messages:
    74
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #12
    yeah,
    that's the first thing that comes to my mind either,
    probably beacuse of the register_globals the variables you use through the page, variables you get from get, post, cookie or session, all mix up, replace one another...

    check register_globals
     
    yleiko, Aug 2, 2008 IP
  13. blogatom

    blogatom Peon

    Messages:
    264
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #13

    I don't have access to php.ini bcos i am on a shared hosting .
    btw thanks for identifying the problem and its solution :)
     
    blogatom, Aug 2, 2008 IP
  14. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #14
    You should still be able to turn it off with the ini_set() function.
     
    blueparukia, Aug 2, 2008 IP
  15. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #15
    Create a php file containing the below code, save it in your web root and access it with browser
    <?php
    phpinfo();
    ?>
    In the output you will be able to find register_globals.
     
    mwasif, Aug 3, 2008 IP