What are some common PHP coding standards

  1. Set all warnings and errors to ‘on’ in php.ini file.
  2. Set register_ globals to ‘off’ in php.ini file.
  3. Set magic_quotes_gpc to ‘off’ in php.ini file.
  4. Set magic_quotes_runtime to ‘off’ in php.ini file.
  5. Test in browser with javascript errors on.
  6. Make an include file for all settings and variables.
  7. Check data entry with single quotes and double quotes.
  8. Use stripslashes() when fetching data.
  9. Use nl2br() when printing data (entered from a textarea) in html pages.
  10. Use encrypted query strings where required.
  11. One user must not be able to see the records of another user by tampering with the query string variables.
  12. Use image resizing wherever required.
  13. Do not resize images that are smaller than the specified size.
  14. When uploading file, display allowable file types and maximum upload size like: JPG, PNG and GIF Only. Max file size 2 MB.
  15. All forms should come filled in, in case of any errors in filling the form, so that user does not have to type all info again.
  16. All deletes must be confirmed before deletion.
  17. Use lipsum for dummy text. Get it from www.lipsum.com.
  18. When a search or view record is not found, please show a message, “No record found.”.
  19. Check for cascade deletions where required or warn for child record entry.
  20. On all submitted forms, especially contact us pages, please check referrer.
  21. When an ID or a number value is sent in query string to fetch value on page, use the following. if(!is_numeric($_GET[id])){exit;}
  22. Make messages like this:
    • Username is a required field.
    • Your passwords do not match.
    • This category cannot be deleted as it is being referred to in a subcategory. Please delete the subcategory first.
  23. Delete corresponding images when deleting records from database.
  24. All forms must be validated.
  25. Use date picker or date combos whenever date is required to be entered.
  26. Paginate when required.
  27. When writing insert and/or update SQL queries, always write field names and then values. Do not insert or update all values.
  28. When writing database queries, always use quotes, even for numeric fields. This is for MySQL database.
  29. Table names and field names should be like this:
    • Table name: databasename_tablename
    • Field name: tablename_fieldname
  30. Some commonly used field sizes should be as below:
    • username: varachar(20)
    • password: varchar(20)
    • firstname: varchar(15)
    • lastname: varchar(15)
    • fullname: varchar(30)
    • phone: varchar(15)
    • fax: varchar(15)
    • email: varchar(50)
    • address: text
    • city: varchar(20)
    • state: varchar(20)
    • zip: varchar(12)
    • country: int (to come from from country’s table).
    • url: varchar(255)
    • amount/price: double
    • date: date
    • timestamp: bigint
  31. Please set textbox’s max attribute to what it is in the database.
  32. Add server timeout when required.
  33. Test all your applications on multiple browsers.
  34. Give alt tag to all images
  35. Give title tags to images and hyperlinks.
  36. There is always space after a comma, a colon, a semi-colon and a full stop and not before them.
  37. Place an index page (with page title and text as “Access Denied” in all folders without index page to stop directory browsing. Or stop directory browsing using htaccess file.
  38. Show dates in full date format (January 10, 2012)
  39. Make admin login window database driven.
  40. All forms submitted, leading to select statements most have GET method.
  41. All views must be ordered by their respective fields.
  42. In user manager, the application must not be able to delete self and must not be able to delete the admin level user.
  43. Password protect admin folder with database driven module. Do not depend on password protecting admin folder.
  44. Use meta tag to redirect to log out page for auto log out when required.
  45. Always use die() with queries.
  46. Set auto complete off for login forms.
  47. Stripslashes() in email messages.
  48. Use substr where required to show long messages like “Lorem ipsum dorit…”.
  49. Format numbers as 24.00 where required.
  50. Spell check
  51. Write recommended size for pictures
  52. Contact and similar pages should go to thank you page.
  53. Required field must be marked with *.
  54. Use inner joins where required.
  55. Use enum data type where required.
  56. Close connections at page end or before redirection.
  57. Clean up test files before uploading.
  58. Use frame busters where required.
  59. Centre pop up windows.
  60. Delete images before updating them. Either check if exists before deleting or use @unlink.
  61. Mark all required fields with * in all forms.
  62. To get file path, use the following as it works on Apache and IIS.
    • $url_to=”http://”.$ HTTP_HOST.$SCRIPT_NAME;
  63. Set different session names for admin and public users.
  64. Remove all test email addresses that send forms to you.
  65. Some sample messages at below.

Signup: Thank you very much for registering. Your account is now active and ready to use.

Contact Us: Thank you for contacting us. Your message has been sent to the concerned department and you will be contacted back shortly.

 

Profile Update: Your profile has been updated successfully.

 

Bug report submission message: Thank you very much for your time. Your reported bug/error has been routed to the concerned department for further action.

 

Lost Password: Your login information has been mailed to your email@domain.com.

 

Wrong Login info for Lost Password: Invalid login information; please provide the email address you used when you registered with us.

 

Lost Password Email:

 

Subject: Your SITE_NAME Login Information

 

Dear Member Name,

 

Your SITE_NAME login information is as below.

User Name: username

Password: password

The SITE_NAME Team

Registration Email to the member:

Subject: Welcome to SITE_NAME

Dear Member Name,

We welcome you to SITE_NAME. Your login information is as below and you can change your password anytime after logging in to the web site.

User Name: username

Password: password

The SITE_NAME Team

Leave a Reply

Your email address will not be published. Required fields are marked *


five + 6 =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>