+ Reply to Thread
Results 1 to 9 of 9

Thread: $_SESSION data being lost when the page refreshes

  1. #1
    Hydrargyrum is offline x10Hosting Member Hydrargyrum is an unknown quantity at this point
    Join Date
    Nov 2007
    Posts
    27

    $_SESSION data being lost when the page refreshes

    Long story short, upon logging in, the following code is executed:
    $_SESSION['LoggedIn'] = 1;

    When I run this on my personal server, it works perfectly. The rest of the code sees that $_SESSION['LoggedIn'] is 1; and forwards the user to a nice little member area where they can make changes to their account and whatnot.

    Unfortunately, the session seems to be clearing itself when I try to run this code on x10hosting. I Googled this problem and most people recommend changing something in the php.ini file, but I obviously can't do that, so what how do I work around it?

  2. #2
    morshed's Avatar
    morshed is offline x10Hosting Member morshed is an unknown quantity at this point
    Join Date
    Mar 2009
    Location
    Bangladesh
    Posts
    4

    Cool Re: $_SESSION data being lost when the page refreshes

    Quote Originally Posted by Hydrargyrum View Post
    Long story short, upon logging in, the following code is executed:
    $_SESSION['LoggedIn'] = 1;

    When I run this on my personal server, it works perfectly. The rest of the code sees that $_SESSION['LoggedIn'] is 1; and forwards the user to a nice little member area where they can make changes to their account and whatnot.

    Unfortunately, the session seems to be clearing itself when I try to run this code on x10hosting. I Googled this problem and most people recommend changing something in the php.ini file, but I obviously can't do that, so what how do I work around it?
    Did you start a session in the first place?? You need to execute session_start() first!

  3. #3
    ichwar's Avatar
    ichwar is offline Community Advocate ichwar is an unknown quantity at this point
    Join Date
    Dec 2008
    Location
    NC, USA
    Posts
    1,454

    Re: $_SESSION data being lost when the page refreshes

    Quote Originally Posted by morshed View Post
    Did you start a session in the first place?? You need to execute session_start() first!
    yes, a lot of people make that mistake. That drove me nuts at first actually, I couldn't figure out why my sessions weren't working.:laugh:

  4. #4
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: $_SESSION data being lost when the page refreshes

    To add a little more information, there is a PHP directive set in the php config file to autostart sessions. It sounds like your other server does autostart sessions, but x10 does not.
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  5. #5
    ichwar's Avatar
    ichwar is offline Community Advocate ichwar is an unknown quantity at this point
    Join Date
    Dec 2008
    Location
    NC, USA
    Posts
    1,454

    Re: $_SESSION data being lost when the page refreshes

    Quote Originally Posted by garrettroyce View Post
    To add a little more information, there is a PHP directive set in the php config file to autostart sessions. It sounds like your other server does autostart sessions, but x10 does not.
    correct, I was not using x10.
    Edit:
    anyways, does php throw an error if the session is called when not yet started?
    Last edited by ichwar; 05-30-2009 at 07:02 PM. Reason: Automerged Doublepost

  6. #6
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: $_SESSION data being lost when the page refreshes

    You can check if the session is started already and if it is not, start one, like this:

    Code:
    if (empty(session_id())) {
         if (!session_start()) {
              exit('Session could not be started');
         }
    }
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  7. #7
    Hydrargyrum is offline x10Hosting Member Hydrargyrum is an unknown quantity at this point
    Join Date
    Nov 2007
    Posts
    27

    Re: $_SESSION data being lost when the page refreshes

    As it turns out, I did forget to start the session. My server automatically starts sessions and x10hosting does not.

  8. #8
    larosti is offline x10Hosting Member larosti is an unknown quantity at this point
    Join Date
    Sep 2009
    Posts
    1

    Question Re: $_SESSION data being lost when the page refreshes

    Ok, so I'm having a very similar problem...
    I have my web, open it up on localhost (my laptop), under Firefox AND IE8, and have everything running perfect with the login scripts.
    Now, I uploaded it to my x10hosting, running under FF, everything's cool, but under IE, the session does not seem to prevail.
    I've googled my butt off, yet the solution does not pop-up, but I found out what the problem seems to be.
    Apparently, in IE, everytime a session_start() is sent, a new session is created, regardless that one was already active or not. As a consequence, the session I "log to" with $_SESSION['username'] and $_SESSION['password'], does not prevail.

    I hope I explained myself correctly, so someone can help me out, 'cause I'm kinda going nuts about this.
    Thanks in advance.

  9. #9
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: $_SESSION data being lost when the page refreshes

    1. session_start() at the beginning of the script, before anything is sent to the browser, even a blank line.
    2. Make sure your IE is accepting cookies from x10.
    Nothing is always absolutely so.

+ Reply to Thread

Similar Threads

  1. Ads on Every Page?
    By ThaoD in forum Free Hosting
    Replies: 5
    Last Post: 08-23-2005, 05:44 PM
  2. Catch data from HTML page
    By sizzla in forum Scripts & 3rd Party Apps
    Replies: 2
    Last Post: 06-15-2005, 04:48 AM
  3. Desparate for help wiht Front Page!!!
    By katyW in forum Free Hosting
    Replies: 3
    Last Post: 05-31-2005, 06:47 PM
  4. Cannot edit in Front Page
    By katyW in forum Free Hosting
    Replies: 9
    Last Post: 05-26-2005, 06:34 PM

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
x10hosting free hosting for the masses
dedicated servers