If server has default config set not to show the errors use this at the begining of your php file:
error_reporting(E_ALL);
ini_set(‘display_errors’, ’1′);
If server has default config set not to show the errors use this at the begining of your php file:
error_reporting(E_ALL);
ini_set(‘display_errors’, ’1′);
1. If a method can be static, declare it static. Speed improvement is by a factor of 4.
2. Avoid magic like __get, __set, __autoload
3. require_once() is expensive
4. Use full paths in includes and requires, less time spent on resolving the OS paths.
5. If you need to find out the time when the script started executing, $_SERVER[’REQUEST_TIME’] is preferred to time()
6. See if you can use strncasecmp, strpbrk and stripos instead of regex Read the rest of this entry
The ternary operator is a shortcut comparison operator that replaces an if-else statement in a PHP script. If you use a lot of comparison statements in your scripts, this can greatly reduce the number of lines of code. The ternary operator is really very simple to use, but it does tend to confuse newbie PHP programmers.
The ternary operator is only used for assignment of values to variables and to reduce the lines of code and compact PHP statements. Although it is a little more difficult to read, once you understand how it operates, it is simple to use and understand.
Read the rest of this entry
Most new web developers have heard of SQL injection attacks, but not very many know that it is fairly easy to prevent an attacker from gaining access to your data by filtering out the vulnerabilities using MySQL extensions found in PHP. An SQL injection attack occurs when a hacker or cracker (a malicious hacker) attempts to dump the data in a database table in a database-driven web site. In an unprotected and vulnerable site, this is pretty easy to do.
In order for an SQL injection attack to work, the site must use an unprotected SQL query that utilizes data submitted by a user to lookup something in a database table. The data could be from a search box, a login form or any type of query used to look up data using data input by user. It also means that querystring data used to query a database can create vulnerabilities.
Read the rest of this entry
Many older sites written in PHP as well as many newer sites that evolved from older legacy code will find their sites broken when their servers are upgraded to PHP 5.3. That’s because many older PHP functions and INI directives are now formally deprecated in version 5.3.
This will not just affect ancient web sites written with very old versions of PHP. Many fairly current PHP sites, including several popular shopping carts, will crash when their hosting company upgrades the server to PHP 5.3. As a code system evolves, it is not unusual for some older code to remain.
Read the rest of this entry