Page 1 of 1
php login help
Posted: Tue Apr 28, 2009 10:13 pm
by burndahows
Hey there!
I'm new to PHP, i've been working with VB6 & .NET before but never been on PHP. I have a few background on HTML but that's about it. anyway I currently have a new project and I need your help.
I would like to know how to make a login page using mysql database and then sort of redirect them to a 'personal' page where they can access files or something etc. I've searched some code over the internet and found them quite useful but never really suited my needs. I can login to a page and then redirect them to a members page but the problem is after I refreshed the members page, it won't show anything, i mean the page is just blank. i will need to login again to display the page. I wanted to refresh the page and then sort of refresh the 'mysql connection' sort of updating the values on the page when i refresh it. thanks in advance
Re: php login help
Posted: Tue Apr 28, 2009 10:51 pm
by it2051229
ding ding ding.. congratulations, you have successfully confused me... would you like to try again?
Re: php login help
Posted: Wed Apr 29, 2009 12:36 am
by burndahows
ok sorry about that
After I have logged in successfully to my 'login page', the 'members page' appears
and displays information, data regarding that member. What happens is after I refresh the
'members page', it will show a blank page. what i want is when I refresh the page, i wanted to
refresh the 'connection' to the mysql and update the information, data of that member.
Re: php login help
Posted: Wed Apr 29, 2009 1:07 am
by it2051229
hmmm... my guess is that something is wrong with the flow of your pages... mind posting your code so we can see?
Re: php login help
Posted: Wed Apr 29, 2009 1:34 am
by burndahows
I got it working!!!
Another question though, how can I add an expiration, let's say after 30 minutes of being logged in, the page automatically redirects to the login page for the member to log in again?
And also when the user closes the members page and then went back on it again, let's say the member navigates to another page and then hit the 'back button', it will go to the login page instead of the member page?
Please tell me if I'm making myself clear. thanks in advance
Re: php login help
Posted: Wed Apr 29, 2009 10:52 pm
by it2051229
well i need to know how do you store the user's data to know if the user is currently logged in or not? Are you using Session? or are you using Cookies? but anyways, whatever of the two you're using, sessions by default isssss i think lasts for 30 seconds without inactivity.. cookies, can stay permanently but you can put a time limit on it.
Re: php login help
Posted: Wed Apr 29, 2009 11:15 pm
by burndahows
I'm using sessions. How will i know if the sessions time out? How can i set the timeout? Is it done through the php.ini or in the php code itself? And after it times out, how can i redirect them to the login page?
thanks in advance
Re: php login help
Posted: Thu Apr 30, 2009 1:07 am
by burndahows
okay i've used "session_set_cookie_params(60);" to set the session to 60 seconds and then "if (!$_SESSION["valid_user"])" to validate if a certain session is active and if not, redirects to the login page.
another question though, how do i edit or display a message on the login page after it redirects, say a message saying 'timeout' or something like that.
let's say this is the original login page:
Welcome!
Username: __________
Password: __________
and after the session expires, this will be the "new" login page:
Session timeout. Please login again
Username: __________
Password: __________
I really need help on this. thanks again
Re: php login help
Posted: Thu Apr 30, 2009 1:58 am
by it2051229
well i havent done yet what you're trying to achieve but i have an idea..
since you made you use of an IF statement to check whether the session expired or not I'm assuming you're making use of the function
header("Location: ") as for redirecting...
when calling the page where to be redirected when sessoin expired, you try to add additional values.. Like for example user should be reidrected to index.php when session expired so i do something like:
Code: Select all
if(session has expired)
{
header("Location: index.php?status=sessionexpired");
}
then on your index.php, you try to detect the "status" which is found on the URL
so on index.php...
Code: Select all
if(isset($_GET["status"]) && $_GET["status"] == "sessionexpired")
{
echo "YOUR SESSION EXPIRED DUDE!";
}
Re: php login help
Posted: Thu Apr 30, 2009 2:07 am
by burndahows
wow! it worked like a charm. thanks man.