How do i secure data when: - Getting It from the database. (ie login) - Putting it into the database. (ie registration) I already have the passwords in md5.
Not talking about SSL, im talking about code to make my php safer... This is what i currently have (for my registration page) $fullname = mysql_real_escape_string($_POST['fullname']); $address1 = mysql_real_escape_string($_POST['address1']); $address2 = mysql_real_escape_string($_POST['address2']); $city = mysql_real_escape_string($_POST['city']); $state = mysql_real_escape_string($_POST['state']); $country = mysql_real_escape_string($_POST['country']); $zip = mysql_real_escape_string($_POST['zip']); $email = mysql_real_escape_string($_POST['email']); $password = md5(mysql_real_escape_string($_POST['password'])); $confirmpassword = md5(mysql_real_escape_string($_POST['confirmpassword'])); $paypal = mysql_real_escape_string($_POST['paypal']); $tos= (isset($_POST['tos'])) ? 'Yes' : 'No'; $old= (isset($_POST['old'])) ? 'Yes' : 'No'; PHP:
What are you talking about? Im not asking how to connect to a database! Your 'answers' are not even close to what im asking.
in phpmyadmin donot allow any other host to connect to db other than localhost Also be polite with me Regards Alex
yes i do you have not explained what knd of security u need and why ,what lack of security you feel .So that i can better understand your problem and advise you. Regards Alex
Why do i want high security? Because the site will be dealing with cash, I dont want anyone getting into the database, stealing personal information, etc. Not sure why I had to say why i wanted security, would think thats pretty obvious for any website. The only security im talking about is php (inserting information into mysql and reading information from the mysql) ie: mysql_real_escape_string
<?php function quote_smart($value = "", $nullify = false, $conn = null) { //reset default if second parameter is skipped $nullify = ($nullify === null) ? (false) : ($nullify); //undo slashes for poorly configured servers $value = (get_magic_quotes_gpc()) ? (stripslashes($value)) : ($value); //check for null/unset/empty strings (takes advantage of short-circuit evals to avoid a warning) if ((!isset($value)) || (is_null($value)) || ($value === "")) { $value = ($nullify) ? ("NULL") : ("''"); } else { if (is_string($value)) { //value is a string and should be quoted; determine best method based on available extensions if (function_exists('mysql_real_escape_string')) { $value = "'" . (((isset($conn)) && (is_resource($conn))) ? (mysql_real_escape_string($value, $conn)) : (mysql_real_escape_string($value))) . "'"; } else { $value = "'" . mysql_escape_string($value) . "'"; } } else { //value is not a string; if not numeric, bail with error $value = (is_numeric($value)) ? ($value) : ("'ERROR: unhandled datatype in quote_smart'"); } } return $value; } ?>
Note: If magic_quotes_gpc is enabled, first apply stripslashes() to the data. Using this function on data which has already been escaped will escape the data twice. Note: If this function is not used to escape data, the query is vulnerable to SQL Injection Attacks.
You should limit the type of data that each goes through. For example, in zip, you probably want to make sure that it's an integer. As for the password, you probably would want to hash it with a salt, and I'm almost sure that you don't need to escape the string if you're hashing it anyway. And you could use some regular expressions to really make it strict, if you seriously feel the need to make this as secure as you possibly can. If it has to do with money and transactions, I'd say be as safe as you can. Also, I think you would want to set a limit here, as well as in your form, since someone could use an remote form to just spam your database with useless ..well, spam.
isnt integer just numbers? If it is, Canadian Zip/Postal codes contain numbers, letters and a space. And im going to add a Captcha to the form.
What you could also do is you could automatically assign a 'guest' session ID to everyone that goes on your website, and then in the form, create a hidden input that's something like: <input type="hidden" value="'. $_SESSION['id'] .'" /> HTML: And then, in your processor file, check that the current session id of the user accessing that processor page is the same as the posted session id. This will prevent people from using remote forms.
Whoa whoa, hidden input fields? Terrible idea. You'll probably want to have extreme amounts of verification on any data passed to/from the database, and I would try and avoid GET/POST so that users can't manipulate URLs. Sessions are a good idea.
I don't see why using POST and hidden input fields is a terrible idea. If the session IDs don't match up, then that means that they're not using the form from his website, therefore disallowing it. The only way the IDs can match up is if they're on that site for both the form submission and processing.