+ Reply to Thread
Results 1 to 5 of 5

Thread: Preventing SQL Injections with PHP

  1. #1
    Woolie's Avatar
    Woolie is offline x10 Lieutenant Woolie is an unknown quantity at this point
    Join Date
    Jun 2005
    Location
    The Fletcher Memorial
    Posts
    431

    Preventing SQL Injections with PHP

    Thought I'd write up an article explaining the risks of SQL injections and how to prevent them. Useful if you're developing database driven applications.

    Clicky Here

  2. #2
    Livewire's Avatar
    Livewire is offline Abuse Compliance Officer Livewire is a glorious beacon of lightLivewire is a glorious beacon of light
    Join Date
    Jun 2005
    Location
    Behind a keyboard.
    Posts
    8,998

    Re: Preventing SQL Injections with PHP

    Now THIS'll come in handy for me - theres a systems project a group is working on for my college (I'm in that group actually). Granted, the users able to access the system aren't going to be doing this stuff anyways but I'm still gunna code against it

    Thanks ^_^


    Edit: Hey, quick question: Could this also be countered by changing the SQL users privileges so all they can do is select statements? I mean, they can't delete something if the user that they're logging in as can't use a delete statement, right?
    Last edited by Livewire; 01-28-2007 at 11:23 PM.


    TOS breakers will be suspended regardless of race, creed, national origin, hair color, or favorite food. Thanks for your understanding!

  3. #3
    Woolie's Avatar
    Woolie is offline x10 Lieutenant Woolie is an unknown quantity at this point
    Join Date
    Jun 2005
    Location
    The Fletcher Memorial
    Posts
    431

    Re: Preventing SQL Injections with PHP

    Thats correct yes, you can modify the permissions for a the user and this will prevent them from causing harm. This is a perfectly good way of doing things, and in production servers, it is recommended. However it can cause problems for the administration system for the site as you can't delete or modify records. The way to get around this is to have another field in the tables (for example a posts table) that is a boolean value "deleted". Then when you want to delete a field from in the application, you simply set that value to true, and when displaying the records, don't show any with the deleted field set to true.

    I personally prefer to defensively code against SQL injection attacks because its just good practice and means that when people install your application they don't have to worry about setting up separate user accounts with specific privileges.

    Its personal preference, but yes you can user permissions.

  4. #4
    Livewire's Avatar
    Livewire is offline Abuse Compliance Officer Livewire is a glorious beacon of lightLivewire is a glorious beacon of light
    Join Date
    Jun 2005
    Location
    Behind a keyboard.
    Posts
    8,998

    Re: Preventing SQL Injections with PHP

    Killer, means I dun need to recode my website for the 400th time

    The system for college I do need to do your thing with though, I already know that even though the server is using users, they're also all set to "all privileges." If you've taken so much as one class there you could destroy the whole site :S


    TOS breakers will be suspended regardless of race, creed, national origin, hair color, or favorite food. Thanks for your understanding!

  5. #5
    Woolie's Avatar
    Woolie is offline x10 Lieutenant Woolie is an unknown quantity at this point
    Join Date
    Jun 2005
    Location
    The Fletcher Memorial
    Posts
    431

    Re: Preventing SQL Injections with PHP

    ouch yea that sounds dangerous... just make sure you use mysql_real_escape_string() on stuff and you really can't go wrong.

+ Reply to Thread

Similar Threads

  1. Ever Been Suspended For Using PHP?
    By dragoneye_xp in forum Off Topic
    Replies: 26
    Last Post: 08-16-2009, 07:17 PM
  2. [PHP] Variables in PHP
    By Bryon in forum Tutorials
    Replies: 15
    Last Post: 01-29-2009, 09:46 AM
  3. tons of PHP Resources
    By Chris S in forum Scripts & 3rd Party Apps
    Replies: 10
    Last Post: 01-16-2009, 10:07 AM
  4. [PHP] PHP For Starters
    By Complex in forum Tutorials
    Replies: 24
    Last Post: 06-14-2008, 11:40 PM
  5. Unstand PHP?
    By o0slowpaul0o in forum Tutorials
    Replies: 8
    Last Post: 01-07-2008, 09:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers