Forum Moderators: coopster

Message Too Old, No Replies

Login system general question

         

matthayzon89

12:13 pm on Oct 1, 2011 (gmt 0)

10+ Year Member



Hello,
I am new to php and mysql and I had a general question about creating a login system.

Right now, I have a website that properly adds users to a database after they register.

Now, I am trying to create a login system for the registered users.

The user types in the username and password combination on the home screen and click 'login' which executes the login.php script which successfully verifies the user name and password combination.

My main question is, how do I customize my website for each particular user once they are back to the home screen?

For example, on my home screen where the login box was... if I logged in as 'Bob111' I would like for it to say "Welcome back Bob111"...

it seems that once I verify the username and password combination in my login.php script, it gets lost once I am back to home.php screen... would I need to use a SESSION? if I need to use SESSION and I chose not to, is the only other way to make it work, is to have all the scripting in one .php file pretty much?

penders

1:47 pm on Oct 1, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



By the sounds of it, you are not actually 'logging a user in' to your site? Just the current page/request? What do you do when the username/password validates successfully?

In order to log a user in, you need to somehow maintain state between pages/requests. A session enables you to do this. Or, you could simply use a cookie, or even a parameter in the URL (messy). Or use HTTP Authentication - the browser maintains state to some extent.

...is the only other way to make it work, is to have all the scripting in one .php file pretty much?


You couldn't really make it work. Your website could only consist of a single page. But as soon as the user refreshed the page they would be logged out.

enigma1

2:49 pm on Oct 1, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just to add that you also need to store the customer info/data in a database or file when they register. Then when they login, you could pull-in the name of the customer from the database and display it. The rest is explained in the post above.

matthayzon89

8:35 pm on Oct 1, 2011 (gmt 0)

10+ Year Member



Once the username and password combinations are validated... thats where I get stuck lol.

So what is the best/ most efficient way to create a login system...? using sessions or cookies?

Thanks for the responses!

@enigma1 yeah I know that all the user info should be saved in the database, and should be pulled out after the user logged in... thanks for the response, I appreciate it:)

rocknbil

4:26 pm on Oct 3, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you're using sessions, you're using cookies. When you execute session_start(), it sets the cookie PHPSESSID which is what maintains the connection between the client and PHP.

There is no "best" way, it's what appropriate to what you're doing - but using sessions does a lot of stuff that you'd otherwise have to do manually (like setting cookie expiration, etc.) So yeah, sessions will probably be best for you.