Don’t Use require() or include() to include dynamic pages from remote sources

Posted by simon at November 20th, 2007

I created a web statistics application a few years back, it was quite a big application and sometimes needed certain functionality on another server. To request this functionality I would use the PHP require() function to execute the remote file

require("http://www.remoteurl.com/generateStatsSummary.php?accountID=$ID&useDate=2007-11-20");

Then a few days back the main server this application is hosted on got hacked into and had to be rebuilt with new versions of MySQL and PHP installed. The application then decided to stop working, in the end I worked out that the more recent versions of PHP don’t allow you to pass query strings to remote files using the require() or include() functions; you must use file_get_contents() instead!

Posted in PHP, Web Development| No Comments | 

PHP Function: Email harvester

Posted by simon at November 8th, 2007

Here is the PHP function I used to collect email addresses from my Outlook express sent items data file. You pass it text and it will return an array of all email addresses that are in the text. Enjoy!

function extract_emails_from($string){
preg_match_all("/[._a-zA-Z0-9-]+@[._a-zA-Z0-9-]+/i", $string, $matches);
return $matches[0];
}

Posted in PHP, Web Development| No Comments | 

PHP Script: MySQL, database-wide engine modification

Posted by simon at November 5th, 2007

2 large MySQL databases (3 gigabytes worth of data and 2,600 tables) somehow managed to corrupt last week and could not be repaired. It should have been a straight forward task for the outsourced Indian server administrators to restore a backup from a previous day but it wasn't!

In the end they managed to restore a backup of both databases but for some reason they restarted the MySQL server with skip-innodb, so rather than using the desired InnoDB storage engine the databases were restored using the MyISAM storage engine. The application that needs to use this database is a high usage web statistics application that cannot run using MyISAM without 20% of the tables corrupting every other day. So MyISAM just isn't acceptable.

You cannot just issue an alter database command and change the storage engine database-wide, the only option you have is alter table. With 2,600 tables that just isn't practical so I created a PHP script to change the engine type for all tables in a MySQL database. (more...)

Posted in PHP, Web Development| No Comments | 

Wordpress code highlighter plug-in

Posted by simon at October 30th, 2007

Initially I tried to install Dean's code highlighter from the Wordpress plug-in directory but I couldn't get it to work and it didn't seem to highlight my code at all. So instead I installed the other code highlighter that was available. It seemed to work without any problems until I noticed that it was adding a random bit of PHP code </odbc_num_fields($result);++$i)>. (more...)

Posted in Web Development| No Comments |