FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Get previous login username





kv
I have a login page. I want to retain the previous logged in user name on that computer so that when the user visits next time, he need not type user name again. I know this needs cookies, but can somebody tell me how to do this in php?
Ducksteina
Code:
<?PHP
setcookie("TestCookie", "Username"); // sets the cookie TestCookie with the value Username
echo $_COOKIE["TestCookie"]; // outputs the cookie TestCookie
Stubru Freak
It's worth noting that cookies have to be set before any output.
mathiaus
depending on how secure you need your pages you may require to set a cookie for the password (encrypted!) and on every page load query the database to check otherwise they can just change the username and their logged in as someone else.

Another way not as secure but it stops the user doing this is to encrypt the username somehow and set a second cookie for this. On every pageload check that the encrypted cookie name is the same as the normal name when you encrypt that as well. If not warn them! Twisted Evil
kv
Ducksteina wrote:
Code:
<?PHP
setcookie("TestCookie", "Username"); // sets the cookie TestCookie with the value Username
echo $_COOKIE["TestCookie"]; // outputs the cookie TestCookie


Somehow this didn't work for me. I put the echo $_COOKIE["TestCookie"]; in the next page accessed as said in the manual. I also checked the browser's cookies. It is not setting any cookies. Cookies are enabled in the browser. Is there any other setting (like php.ini) which needs to be set?
mathiaus
you need to set a time in seconds
Code:
setcookie("Username", $username, time()+36000); //10 hours
kv
Yes. That was the problem. It worked. Thanks.
Related topics
Loading time?
Password problem
Somethin is wrong with my account
This is really ticking me off!
havn't logged on to frihost for a long time, how to con pnl?
Problem In Opening Home Page?
NEED FORUM FIXED!
Can't Login - Invaild username
I installed word press but i don't pay my frihost points...
Howto retrieve info from other websites ?
Why are .info domains cheaper than .com or .net domains?
help with login to display the current username
How to get windows username from Flash or ActionScript 3?
Where do i put my info databse name username and login???
This topic is locked: you cannot edit posts or make replies.    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.