I want to / am busy with completely re-writing my whole site. At this point I am working on what I call "members- and safety engine". I have been reading a lot about security and SQL injection, and it is pretty complicated. ps. My site is more a hobby than a professional money making website with about 250+ members.
For username AND password I only allow the characters a-z, A-Z and 0-9. I check this in the if(isset(post))-function with:
if(ctype_alnum(mysql_real_escape_string(stripslashes($string))) == false) {
header to error-page; exit;}
else {continu with script}
This check is done for both the password and the username.
When somebody tries to login with a unknown username or a known username with a wrong password the action is logged (inserted) in a special table, including IP address. After 10 attempts to login with an unknown username, or 6 attempts with a wrong password the IP address is blocked from the members area and on all the non-member pages forms and submit of the forms are not shown and they are not useable because of this ip-block. I even have this ip-check as a line when the form is submitted... if the ip is in the table, header(to error page); exit;.
My questions:
- Do I have to make a security check when I place the
IP address in a string?
$xip = $_SERVER['REMOTE_ADDR'];this$xipis inserted in the table when trying to log in with a unknown user or with wrong password. - Is this a (pretty) safe environment against hacking and SQL injection?
- If not? I really appreciate help and suggestions (writing the complete solution here is very much appreciated, but I learn a lot more when you send me on the right path to the solution)
- Do I also have to run the "ctype_alnum" check when I retrieve this info from the
$_cookieor the$_session?
ps. I am dutch, so almost all of my table names, column names, form input-field-names etc etc etc have a dutch word for it. I am still working on it, but when the site is finished you will not find the word "password", "pass", "user", "userid", or anything like that on my site.