


1. Become good friends with the PHP manual
2. Turn on Error Reporting
Error reporting is very helpful when developing PHP. You can find errors in your code that you have not found before, because not all Bugs will prevent the program from running. When the product is officially used, it is necessary to turn off error reporting, otherwise customers will see a bunch of strange characters and not know what they mean.
3. Use IDE
IDE (Integrated Development Environments) is a very helpful tool for developers.
The wilderness recommends netbeans IDE here.
4. Try to use a PHP framework
5. Learn the DRY method
DRY stands for Don't Repeat Yourself, it is a valuable programming concept, no matter what language it is. DRY programming, as the name suggests, ensures that you don't write redundant code.
6. Use spaces to indent code to improve readability
7. “Tier” your Code
Tier your application into different parts of the code. This allows you to easily change your code in the future. Such as the commonly used MVC pattern.
8. Always use
9. Use meaningful, consistent naming conventions
10. Comment, comment, comment
11. Install MAMP/WAMP
12. Limit the running time of your script
Usually the running time of PHP scripts is limited to 30 seconds, after which PHP will throw a fatal error.
13. Use OOP
14. Know the difference between double quotes and single quotes
15. Don’t put phpinfo() in the root directory of the website
16. Never trust your users
17 .Encrypted storage of passwords
Rebuttal:
Keep in mind, however, that MD5 hashes have long since been compromised. They're absolutely more secure than not, but, with the use of an enormous “rainbow table,” hackers can cross reference your hash. To add even more security, consider adding a salt as well. A salt is basically an additional set of characters that you append to the user's string.
18. Use visual database design tools
as DBDesigner and MySQL Workbench
19. Using output buffering
Rebuttal: Though not required, it's generally considered to be a good practice to go ahead and append the “ob_end_flush();” function as well to the bottom of the document . P.S. Want to compress the HTML as well? Simply replace “ob_start();” with “ob_start('ob_gzhandler’)”;
Refer to this Dev-tips article for more information.
20. Protect your code from SQL injection
$username = mysql_real_escape_string( $GET['username'] );
$id = $_GET['id'];
$statement = $connection->prepare( "SELECT * FROM tbl_members WHERE id = ?" );
$statement->bind_param( "i", $id );
$statement->execute();
By using prepared statements, we never embed the user's inputted data directly into our query. Instead, we use the “bind_param” method to bind the values (and escaping) to the query. Much safer, and, notably, faster when executing multiple CRUD statements at once.
21. Try ORM (object relational mapping)
ORM libraries for PHP like Propel, and ORM is built into PHP frameworks like CakePHP.
22. Cache database driver pages
Such as:
// TOP of your script
$cachefile = 'cache/'.basename( $_SERVER['SCRIPT_URI']);
$cachetime = 120 * 60; // 2 hours
// Serve from the cache if it is younger than $cachetime
if (file_exists($cachefile) && (time() - $cachetime include($cachefile);
echo "";
exit;
}
ob_start(); // start the output buffer
// Your normal PHP script and HTML content here
// BOTTOM of your script
$fp = fopen($cachefile, 'w'); // open the cache file for writing
fwrite($fp, ob_get_contents()); // save the contents of output buffer to the file
fclose($fp); // close the file
ob_end_flush(); // Send the output to the browser
23. Use caching system
- Memcached
- APC
- XCache
- Zend Cache
- eAccelerator
Cookie data, like any data passed on the Web, can be harmful. You can validate cookie data with either the htmlspecialchars() or mysql_real_escape_string().
25. Use a static file caching system
Such as Smarty is a powerful template system with built-in caching.
26. Profiling your code
Profiling your code with a tool like xdebug can help you to quickly spot bottlenecks and other potential problems in your PHP code. Some IDEs like Netbeans have PHP profiling capabilities as well.
27. Coding standards
such as Pear standard.
28. Keep Functions Outside of Loops
You take a hit of performance when you include functions inside of loops. The larger the loop that you have, the longer the execution time will take. Take the extra time and line of code and place the function outside of the loop.
Editor's Note: Think of it this way. Try to remove as many operations from the loop as possible. Do you really need to create that variable for every iteration of the loop? Do you really need to create the function each time? Of course not.
29. Do not copy additional variables (in fact this is questionable, see the explanation below)
For example:
$description = strip_tags($_POST['description']);
echo $description;
can be written as follows:
echo strip_tags($_POST['description']);
Rebuttal: In reference to the comment about “doubling the memory,” this actually is a common misconception. PHP implements "copy-on-write" memory management. This basically means that you can assign a value to as many variables as you like without having to worry about the copied data actually being. While it's arguable that the "Good" example exemplified above might make for cleaner code, I highly doubt that it's any quicker.
That is to say, PHP implements the "copy-on-write" memory management method. The first code above will not occupy double the memory. Therefore, Rebuttal seriously doubts whether the second method of code is really faster than the previous one.
30. Update to the latest version of PHP
31. Reduce the number of database queries
32. Ask questions bravely
places like StackOverflow are good places.

从初学者到专家:五个必备的C语言编译器推荐随着计算机科学的发展,越来越多的人对编程语言充满了兴趣。而C语言作为一门广泛应用于系统级编程的高级语言,一直受到了程序员们的喜爱。为了写出高效、稳定的代码,选择一款适合自己的C语言编译器是很重要的。本文将介绍五个必备的C语言编译器,供初学者和专家们参考选择。GCCGCC,即GNU编译器集合,是最常用的C语言编译器之一

C++和Python,哪个更适合初学者?在这个信息化浪潮席卷全球的时代,编程能力已经成为一项必备技能。而在学习编程的过程中,选择一门合适的编程语言显得尤为重要。在众多编程语言中,C++和Python都是备受初学者关注的两大热门选择。那么,C++和Python到底哪个更适合初学者呢?以下将从各方面对比两者的优劣,以及为什么选择某一种语言更有助于初学者的编程入门

现在我们已经了解了WooCommerce产品及其相关设置,接下来让我们了解一下WooCommerce的税务配置选项。税收设置作为在线商店所有者,您永远不会想搞乱税务规则和问题。WooCommerce在这方面为您提供帮助,提供多种选项来解决所有税务设置,这些设置可能会因您所在的国家/地区和个别商店的要求而异。可以在以下位置找到这些选项:WooCommerce->设置->税。进入税务设置选项卡后,您将看到一个主要的税收设置部分以及三种不同的税级。这些是:税务选项标准费率降低利率零利率税收

初学者指南:如何用Pandas读取HTML表格数据引言:在数据处理和分析中,Pandas是一个强大的Python库。它提供了灵活的数据结构和数据分析工具,使得数据处理变得更加简单高效。Pandas不仅可以处理CSV、Excel等格式的数据,还可以直接读取HTML表格数据。本文将介绍如何使用Pandas库读取HTML表格数据的方法,提供具体的代码示例,帮助初学

标题:编程初学者应该优先学习C语言还是C++?在编程领域,C语言和C++是两种非常重要的编程语言,它们都有自己独特的特点和优势。对于初学者来说,选择学习哪种语言可能会有一些困惑。本文将就这个问题展开讨论,以及给出一些具体的代码示例来帮助初学者更好地了解两种语言的不同之处。首先,让我们来看一下C语言。C语言是一种功能强大且广泛应用的编程语言,它是从汇编语言发

初学者必备:掌握Python中lambda函数的基本使用方法,需要具体代码示例概述:Python是一种简单易学的编程语言,它以其简洁、灵活的语法吸引了众多程序员的喜爱。在Python中,lambda函数是一种特殊的匿名函数,它可以在需要函数的地方直接定义,并且无需给它一个名字。本文将介绍lambda函数的基本使用方法,并提供具体的代码示例,以帮助初学者更好地

对于初学者而言,选择合适的Django版本是一个重要而且必须要面对的问题。Django作为一个高效的Web框架拥有大量的用户和开发者,因此它也拥有多个版本以满足不同产品和应用的需求。但是,如何根据项目需求选择合适的Django版本呢?下面我们将通过一些实例来帮助大家选择适合自己的版本。确认所用数据库Django支持多个数据库,包括MySQL,Postgre

matplotlib是Python中最常用的数据可视化库之一。它提供了各种绘图选项,包括线图、柱状图、散点图等等。本篇文章将教你如何使用matplotlib绘制散点图,同时提供具体的代码示例,以帮助初学者快速上手。一、导入matplotlib模块在开始使用matplotlib绘制散点图之前,首先,需要导入相关的Python模块。代码如下:importpa


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)