![]() |
First Login Script
Hello,
I've created a little project for myself to improve my PHP. I've decided to create a website which uses a login script. I need to allow new users to register and existing users to login. So far I have the register page working: It's a form with a Username, email and password field and the details entered are entered into the database. I'm unsure how to do the login page :-( I need to do something like:
I don't really know how to do this. I was wondering if someone could point me in the right direction? Thanks, Steven |
ok here is the code
PHP Code:
|
Quote:
Retrieve the values via POST from the login form, validate (check that they're strings, length, etc if you want to), escape (using mysql_real_escape_string() for example, if working in MySQL) and then check against the values in the database, e.g. PHP Code:
Check the PHP manual entries for function definitions. |
Quote:
Google search : SQL injection |
I would also say encrypt any passwords before putting them in the database and like SOCK said do some prevention of mysql injections.
|
In revisiting this thread, it occurred to me to pass some additional advice (as per Rendair's comment on encrypting or hashing the password). Most of these things I take for granted and forget to mention. At any rate, here are other notes / tips in no specific order-
Then create a cool web 2.0ish design wrapped around all that, maybe implement an XHR (Ajax) request for the login process, etc. Once you've got it all done, trash it all and redo it as in OOP. ;-) |
Thanks everyone, I really appreciate all of your help! I'm going to give it a shot just now.
SOCK - Thanks for that. A lot of it doesn't make much sense and I don't know how to do. I have however stored the password in encripted md5, I just found out about that today. Can I ask what UserID is? Is it an auto number field given to each user? Thanks Steven |
Quote:
|
Something else to consider when designing the `user` table, make sure you use a UNIQUE index on the `username` column - keep people from registering the same name, and makes the logic simple when registering users.
|
My eyes are getting tired, so I'm going to leave it for today. I've suddenly gotten a strange error:
Quote:
Code:
//Database Structute |
Ok, the error message is really odd. It almost looks like the httpd server isn't parsing PHP correctly and instead outputting all your PHP code. It seems as if it begins with the call to mysql_connect() but I don't see why.
Have you been successfully connecting to MySQL from this or another PHP script? Does this script have the .php extension (or the appropriate extension to parse PHP)? Please use the provided PHP code tags when posting, it makes it much easier to spot errors, e.g. PHP Code:
Make sure magic_quotes is turned "Off", and use mysql_real_escape_string() only. |
I don't know what was wrong there, but I seemed to have fixed it! :-P
I didn't know that addslashes and mysql_real_escape_string() weren't to be used together. Thanks for letting me know! I am getting somewhere now, I have the following: Code:
<?phpNow, when I try to enter a username and password which is stored in the database, I'm being taken to login.html - which means the login was not successful. I don't know why this is happening, because I'm entering the correct details. |
Quote:
|
Tip: you can use the [ php ][ /php ] tags to save having to manually color your code when posting :-)
The query in the script you posted is in the wrong format. You have mixed up INSERT and UPDATE syntax. An INSERT query should look something like: PHP Code:
PHP Code:
|
Alan@CIT> Not to nitpick, but that INSERT format is perfectly fine. You just don't see it as often as the (column list) VALUES (data list) format.
MySQL Manual : INSERT syntax |
Ahh, cool - never knew you could do that :-)
Alan |
Quote:
PHP Code:
This is how I'm using md5: PHP Code:
|
Quote:
PHP Code:
Code:
SELECT COUNT(userID)Quote:
|
PHP Code:
This is what you want to do instead, on both the registration form and the login processing form: PHP Code:
PHP Code:
The other thing you want to look at redoing is the reassignment code. All this PHP Code:
|
Quote:
|
| All times are GMT. The time now is 08:06 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0