What security issues should I look out for in PHP

后端 未结 18 1857
挽巷
挽巷 2020-11-29 01:51

I just starting out learning PHP, I\'ve been developing web apps in ASP.Net for a long time. I was wondering if there are any PHP specific security mistakes that I should be

相关标签:
18条回答
  • 2020-11-29 02:29

    Whenever possible, use prepared statements (tutorial. It's almost a must whenever dealing with user input (I say "almost" because there are a few use cases where they don't work), and even when not dealing with input, they keep you in the habit. Not to mention they can lead to better performance, and are a LOT easier, once you get into the swing of things, than piecemeal sanitizing.

    0 讨论(0)
  • 2020-11-29 02:30

    Always use POST and not GET for important Data...

    0 讨论(0)
  • 2020-11-29 02:35
    1. Always Close you SQL Connection.
    2. Always Release SQL results.
    3. Always Scrub all variables your putting into a database.
    4. When deleteing or dropping from sql use limit 1 just in case.
    5. When developing make sure you have a lock on things to keep the undesirable out. If its open and you know not to load the page right now because it could break something, doesn't mean other people do.
    6. Never use Admin or Root as your server log in name.
    0 讨论(0)
  • 2020-11-29 02:36

    Language Vs Programmer. You can write the most serious vulnerability and you won't get a warning or error message. Vulnerabilities can be as simple as adding or removing 2 characters in your code. There are hundreds of different types of vulnerabilities that affect PHP applications. Most people think of XSS and Sql Injection because they are the most popular.

    Read the OWASP top 10.

    0 讨论(0)
  • 2020-11-29 02:39

    If you're using a mysql database make sure you call mysql_real_escape_string when sending data to the database

    0 讨论(0)
  • 2020-11-29 02:40

    (In no particular order)

    1. Always check that register globals are OFF
    2. Always check that magic quotes are OFF
    3. Make sure you understand SQL injection attacks
    4. Turn OFF error reporting in production

    EDIT: For the "newbies" out there this is a basic why (and since I have time to explain this):

    1. Register globals is an aberration. It's the ultimate security hole ever. For example, if register_globals is on, the url http://www.yourdomain.com/foo.php?isAdmin=1 will declare $isAdmin as a global variable with no code required. I don't know why this "feature" has made it's way to PHP, but the people behind this should have the following tattooed on their forehead: "I invented PHP Register Globals" so we can flee them like pest when we see them!

    2. Magic quotes is another dumb idea that has made it's way to PHP. Basically, when ON PHP will escape quotes automatically (' become \' and " become \") to help with SQL injection attacks. The concept is not bad (help avoid injection attacks), but escaping all GET, POST and COOKIE values make your code so much complex (for example, have to unescape everytime when displaying and data). Plus if one day you switch this setting OFF without doing any change to your code, all your code and/or data is broken and (even more) vulnerable to injection attacks (yes even when ON you are vulnerable).

    3. Your databse data is your most valuable thing on your site. You don't want people to mess with it, so protect yourself and read things about it and code with this in mind.

    4. Again this can lead to security concerns. The error message can give hints to hackes on how your code works. Also these messages don't mean anything to your visitors, so why show them?

    0 讨论(0)
提交回复
热议问题