Jump to content

PHP Security


c_pattle

Recommended Posts

I have just made a couple of forms that submit data to a mysql database.  I was wondering what measures I need to make to in order to keep the whole thing very secure.  At the moment I have stripped the inputs of tags and forward slashes.  Is there anything else I should do?

 

Also some field in the form allow the user to enter a url.  With these fields I have not stripped them of forward slashes.  Is this a bad idea?  Should I do something like replace the forward slashes with something else and then reverse this process every time I extract that data from the database?

Link to comment
Share on other sites

You can never be too safe with stripping stuff out of data submitted to a database. I've personally never built an application that handled URLs, but I might suggest  using str_replace to replace all the / in urls with a '-', then use the same str_replace function when you output the data to replace the '-'s with /. I hope that makes sense.

Link to comment
Share on other sites

Replacing slashes is pointless, and very likely to cause problems when retrieved. If you use the proper escape function before inserting them, you'll be fine. For string type data, it will be mysql_real_escape_string() (or mysqli_real_escape_string(), if you use the improved extensions). For numeric data types, they should be validated and cast as the appropriate type, be it integer, float, decimal, etc.

Link to comment
Share on other sites

Of course it is. Databases would be pretty useless if you couldn't store a full character set in them. The fact that a character is in a database doesn't make it a vulnerability. It's the actual process of how it's inserted or displayed that can be present a problem.

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.