469,616 Members | 1,792 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,616 developers. It's quick & easy.

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.
Feb 16 '08 #1
3 5340
acoder
16,027 Expert Mod 8TB
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.
Feb 16 '08 #2
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.
Feb 17 '08 #3
acoder
16,027 Expert Mod 8TB
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.
Feb 18 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Ruso | last post: by
3 posts views Thread by Beshoo | last post: by
25 posts views Thread by Piotr Nowak | last post: by
4 posts views Thread by Peter | last post: by
6 posts views Thread by KDawg44 | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.