PHP/ Ajax Login without Refresh: Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • burrashiva
    New Member
    • Feb 2008
    • 5

    PHP/ Ajax Login without Refresh: Help

    :( ::)
    Hello there,

    I recently started Web Designing with PHP, Javascript and AJAX.

    I am facing a problem which I will try to explain:
    If I am successful in conveying the problem to you clearly, could you
    pl. suggest me some solution? Thank you,
    Here is the problem details:

    I successfully created a Registration/Login/Logout system with CMS
    features by learning through tutorials/forums like yours, using PHP/MYSQL
    only. Thanks to the internet.

    I want to Ajaxify the code using the Javascript programming and
    XMLHttpRequest Object.

    So the question I asked to myself is:
    Can we login without refreshing the current page? In theory and
    practice I am able to validate/check the username , password and get
    back the results array from mysql without refreshing the page.

    I am facing the Problems after this:
    How do I retain myself in that State of LOGGEDIN situation? The answer
    to this is(probably): $_SESSION variable.
    But at this point I got stuck: Where should I use session_start() and
    where should I assign the SESS_MEMBER_ID ? Is it in the index.php
    which is the main page (which has the login screen) or is it the 'php
    script' which checks for user name, password
    and sends back the results. I tried adding the session code to "php
    script" under the login submit button. It successfully gives me the
    session id.
    However, if I refresh the page, I loose that session ID:

    so, my doubt is where exactly is session ID stored ? On the server or
    on the client machine like a cookie.
    How do we retain it ?

    Its similar to when I log into yahoo / gmail account, even if I
    refresh, I wont be logged out to main screen.
    How is this possible without refreshing the form.

    Could you pl. help on this.
    Thank you very much for your time.
    regards,
    sincerely,
    Prasad.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Hi Prasad, welcome to TSDN!

    You should use sessions on the main page too, so that when the page is refreshed, you don't lose the session.

    Comment

    • burrashiva
      New Member
      • Feb 2008
      • 5

      #3
      thank you @acoder.
      still I am not fully clear of how to do that.
      I have tried similar to your suggestion ie.

      I created a main.php which has session_start() , LOGGEDIN= false;
      on the main.php , there is a section called loginform, which on receiving username,
      password(checks it) then regenerates session ids and then LOGGEDIN is changed
      to TRUE.

      Now the session should remember TRUE but if I refresh, the session information is lost, the main page come back instead of the logged in TRUE status.
      Is there a place on the client computer and server, where I can look for the session id being stored and just confirm myself that it is infact storing the information and checking it during refresh.?

      Ofcourse, I am using Logged in Status to hide some content which is generally visible in LOGGEDOUT status.

      so, I am confused of how to do this ?
      Hope you will clarify me on this ?

      thank you for the earlier post and for the time too.

      prasad.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        I haven't tested this, but when you normally start a session on a page without Ajax, you wouldn't set LOGGEDIN to false, would you? You'd check that the username is set in the session variables. The only part you need to "Ajaxify" is the login. The rest should stay the same.

        Comment

        Working...