Jump to content

PHP security


Logician

Recommended Posts

I have been working on a website for some time now. My work is now 95% finished and now I am starting to look at security, as I am using PHP.

 

My webpage uses HTML FORMS. When most of these forms get send back to the server, 50% of the time PHP is inserting the value of the FORM inputs into MySQL. To give a basic run down, I have a newsletter sign up system.

 

"Enter your e-mail address"... and then the user enters their e-mail and submits.. PHP runs a MySQL query to insert that FORM value into the database along the lines of this:

insert into newsletters (email) values ('.$POST['email'].')

 

I fear this is very vulnerable to injection attack as it means a trouble maker can come along and enter anything they want into my database, potentially wiping it out.

I believe I need to "sanitize" my input with a MySQL "real_escape_string" or something?

 

Is there anything real obvious I should look out for when it comes to PHP security?

Is there a way to forbid all strings/arguments except the few I need or something perhaps?

Link to comment
Share on other sites

Thanks for the information!

 

I don't know what to make of the example given in that manual.

 

$query = sprintf("SELECT * FROM users WHERE user='%s' AND password='%s'",

            mysql_real_escape_string($user),

            mysql_real_escape_string($password));

?>

 

What is %s?

$user and $password are not defined?

 

Do you know where I can find an example of where mysql_real_escape_string is used in my case?... so I can compare it with a process that is familiar to me.

Link to comment
Share on other sites

Thorpe, thank you very much showing me that example! Its made things allot clearer!

What I am going to do is use:

query = 'insert into newsletters (email) values ('.mysql_real_escape_string($_POST['email']).')';

 

 

Would it be wise to use mysql_real_escape_string for all $_POST['']'s?

 

The PHP manual said mysql_real_escape_string escapes special characters. So I am assuming that is everything but letters and numbers? Oh ow, will this also strip the @ symbol?

 

 

Is there anything else you recommend I should look into with PHP security?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.