Articles in the PHP Category
AJAX, PHP »
If you have an AJAX application that uses a PHP back-end app on a different server as your web front-end server (e.g. load balancing, cdn’s, etc), your PHP script will need to send header variables with the allowed content server name(s).
Web browsers are now following a standard for HTTP Access control to prevent client-side Cross Site scripting attacks.
I tested this with Firefox and it simply blocks the request without any error messages. Google Chrome browser will error out with the following message if the access control origin is not set correctly on your PHP script. (woot!)
“XMLHttpRequest cannot load [PHP URL].. Origin [JAVASCRIPT URL] is not allowed by Access-Control-Allow-Origin.”
For example, if the Javascript is hosted on example.com and your PHP app is on example.org.
Below is the PHP script for fixing this error. [see full message for the solution]
MySQL, PHP »
If you ever have the need to find the answer to the following:
- What are the number of tables in a MySQL database?
- What are the number of rows in a MySQL database?
- How much space is the MySQL database using up on the server?
- How many tables there are in a MySQL server?
- How many rows there are in a MySQL server?
One of the quickest ways to find out MySQL reporting stats is using PHPMyAdmin. The software is usually installed on a number of servers by default, so its just a matter of locating where in the program to find this info.
This is an example of what the stats look …
Frameworks, PHP »
Drupal 7 has been released. There are a number of improvements to the system with this release including a new administrative interface, built-in custom content structure (it was a previously a plug-in), improved performance, and an automated testing framework built-in.
For more information, visit the Drupal website: http://drupal.org/drupal-7.0
There are also Drupal release parties on January 7, 2011. http://www.drupal7releaseparty.org/
PHP »
There is currently a bug in PHP 5.2/5.3 for certain numbers to take up all system resources in a 32-bit system using the x87 instruction set (Most Intel/AMD boxes use this instruction set). Systems running 64-bit operating systems are not affected by this bug.
You can test whether your system is running 64-bit by typing the following command in a shell window:
uname -m
If you see i386, you are running a 32-bit server. Listings with x86_64, or amd64 denote a 64-bit machine.
PHP, wordpress »
Here’s a quick fix for WordPress 2.X to WordPress 3.X migration:
Fatal error: Cannot redeclare wp_load_image() (… previously declared in /wp-includes/media.php) in /wp-admin/includes/image.php …)
What causes this? The primary cause is a plugin inside /wp-content/plugins folder that is incompatible with WordPress 3.0. Most likely the plugin developer defined a wordpress function inside their plugin folder, causing a function name redeclaration.
Frameworks, PHP »
If you are running CodeIgniter 1.7.2, there is a security flaw with the file upload class. (fixed on July 12, 2010) The easiest way to install the patch is to use the standalone patch http://codeigniter.com/download_files/CI_1.7.2_201007_sec_patch.zip and unzip the file to the Code Igniter system/libraries folder.
PHP, wordpress »
If you have noticed all your blog images breaking after upgrading to WordPress 3.0 from WordPress MU, you will need to make a simple change to the .htaccess file.
PHP, wordpress »
As an administrator for a WordPress MU install, I’ve been getting comments about the RSS feed in WordPress not fetching the latest feeds. The RSS feed information that appears on the page ranges from a fetch that is a few hours to a day old. I’ve confirmed this is an issue with 2.9. This is an issue for blogs that need to pull alerts from an RSS feed within a timely basis, e.g. every 10 minutes.
The workaround to this is to use the KB Advanced RSS feed plugin instead of the one that’s in WordPress.
Frameworks, PHP »
Reading Excel files in CodeIgniter is actually very easy once you have the right documentation. The first thing you will need to do is utilize the CodeIgniter “Upload” library and add in the Excel Reader library for reading the files. The documentation on the CodeIgniter website in regards to this Excel Reader library is missing some details in implementation. This tutorial will go through the steps of installing the Excel reader library and getting an example implementation working.
MySQL, PHP »
The error message looked like:
“Illegal mix of collations (latin1_swedish_ci,COERCIBLE) and (utf8_general_ci,IMPLICIT) for operation ‘find_in_set’”
I ran into this problem today while importing text from a CSV file. Evidently, the text format of the document had UTF characters, which caused CodeIgniter to error out when it tried to insert it to the database. The line had French characters (The ç in Français) My database fields by default are set to “latin1_swedish_ci” character set.
The fix?
I decided the best way to fix this was to set the Collation option for that specific field in the MySQL database to “utf8_general_ci
