How to set cookies first and then store that in a database?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
indian98476
Forum Commoner
Posts: 78
Joined: Tue Dec 15, 2009 3:24 am

How to set cookies first and then store that in a database?

Post by indian98476 »

i want to set cookies for users logging in so that i can give them back personalised webpages.,...i heard we must create the cookies and then store them in a database....can anyone code me into it?
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: How to set cookies first and then store that in a database?

Post by Apollo »

Cookies are, by definition, stored in the visitors' browser. Not in a database.

See also
indian98476
Forum Commoner
Posts: 78
Joined: Tue Dec 15, 2009 3:24 am

Re: How to set cookies first and then store that in a database?

Post by indian98476 »

so here is my doubt now..
i got say 3 users a,b and c...when anyone logs in for the first time he should get a msg lets say Welcome to our site...
if the same user logs in again he should get a msg lets say welcome back
user's name

if a different user logs in the same browser he should get a msg lets say Welcome to our site
if the user who logged in first again logs in after this he should get welcome back
user's name

so if the first user's value is stored in d browser what bout the value of the next user?
i think u r getting my doubt...if not feel free to ask...
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: How to set cookies first and then store that in a database?

Post by Apollo »

But that's not something I'd do with cookies. Instead, simply store on your server (in a database, for example) which users have already logged in before.

So if someone logs in, you get the 'has_logged_in_before' value for the given username from your database, and display the appropriate welcome message. No need for cookies at all. Works also if someone clears his browser or logs in from another computer.
indian98476
Forum Commoner
Posts: 78
Joined: Tue Dec 15, 2009 3:24 am

Re: How to set cookies first and then store that in a database?

Post by indian98476 »

thanx appollo...i thought cookies were the ones that helped the user give suggestions on the textfield if he has come before for his username...but i learned that it is the work of browser...but how exactly does it do it?
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: How to set cookies first and then store that in a database?

Post by Apollo »

It simply remembers the strings that the user has filled in before in fields called "name", "email", etc.
A bit like caching.
Post Reply