Today I wanted to replace some old PHP 4 code I had to calculate the difference in time between two time stamps and return something like “5 days, 2 hours, 4 mins, 45 seconds”
It seems from googling around there are many different attempts to do this – and most of them work quite well, but the majority have huge bugs in their logic.
Looking within PHP 5.3.x we have a very very neat solution, a few lines of code instead of a whole function
Here it is – easy as pie!
$time_one = new DateTime( $YourFirstTime );
$time_two = new DateTime( $YourSecondTime );
$difference = $time_one->diff( $time_two );
echo $difference->format('%h hours %i minutes %s seconds');
// gives something like "4 hours 5 minutes 2 seconds"
// (depending on the input of course!)
Loving PHP 5.3
We have all seen Google mark websites as “This site may compromise your computer” when it detects a website has been infected with a hack or malware, well this is called the “Safebrowsing list” (Ironically as the sites on it are less than safe to browse!)
You can use PHP and a Google API to tap into this wealth of information, and along with the Zend framework and some code I knocked together you can query this huge database of sites very easily.
I have published the code over on GitHub at: https://github.com/PhilETaylor/Bf_Google_Safebrowsing
Its simple to use (once you have Zend bootstrapped) with an example such as:
$google = new Bf_Google_Safebrowsing ( array ('apikey' => 'YOUR API KEY' ) );
if (TRUE == $google->isListed ( 'http://www.phil-taylor.com' )) {
// Dang! Why is that listed!
}
If its useful to you then great, I dont think many people will be using it daily, but its a handy bit of code to have in our tool chest.
Occassionally in PHP Joomla Extension/Plugin development you need to work out if the current rendered page is inface the default home page. The old way of doing this was to check the Itemid, but later versions of Joomla have a better way.
In order to see if you are on the homepage you can do something like the following snippet of code:
$menu =& JSite::getMenu(); // Load the menu
$active = $menu->getActive(); // Get the current active menu
if ($active->home ==1) { // See if this is the homepage
// Yes! This is the homepage!
} else {
// No this is not the homepage
}
ok the title of this blog post is an oximoron
I read a blog post on another Joomla related site today regarding easy regex’ing and I wanted to share a couple more links that I personally use while developing – and I actually DO use these myself.
This is the first one:
And the second is a plugin for the Eclipse Development platform, I use it in Zend Studio for Eclipse
What a day!
Today, I sat the Zend PHP5 Certified Engineer Certification exam AND PASSED!
This is my first PHP industry qualification (I don’t think there are many PHP certifications apart from the Zend ones!) and now makes me the ONLY Zend PHP5 Certified Engineer in Jersey, Channel Islands, UK!
What does this mean for you? Well it is a certification that puts me apart from other developers and shows the level and commitment I have taken in learning PHP 5 and in applying that knowledge in real word situations. As far as I know, no other Joomla Extension Developer has obtained this grade. (I may be wrong!)
More details about the Zend PHP5 Certified Engineer Certification can be found on the Zend.com website.
Although my name has not yet been added to their yellow pages, you can authenticate my certification by clicking here (Pearson Vue) and entering:
I just want to acknowledge someone here. Andrew Eddie!, the original lead developer on an old project called Mambo – without him, his encouragement, his example, his code, I would never have got into PHP and would never be where I am today. Thank you Andrew – Bitwise Operators (aka Masks in Mambo 4.5) are part of the Exam!!!!!
I am working on a huge application at the moment that requires a whole load of replacements in a text string (Think replacing TLA with Three Letter Abbrev’s)
I googled to see if there was a faster PHP method than str_replace(). The results on the first page gave me a chuckle and a headache.
Here is the link to the search result page
So – Is str_replace faster than preg_replace? or is it that preg_replace is faster than str_replace???
Who knows? Google certainly doesnt…
We are pleased to make public the SVN repository for the xAJAX Plugin for Joomla 1.5 that is being maintained by a group of developers and co-ordinated by ourselves. This announcement is for PHP Developers only. This version of the plugin is NOT for production use but should be used for testing only.
You can download the files from SVN repository at (Use your forge.joomla.org username and password):
http://scm.joomla.org/svn/repos/xajax4joomla/J15_trunk
These plugin files are almost complete and will not change much, we have left security, loading messages and other things down to individual component developers to implment in their components as this is the better way we think, and allows component developers the best environment in which to develop – basically allowing them to do what ever they want with the xAJAX incoming data instead of us imposing restrictions.
We already have 5 components running on this version of the plugin, and we are very confident in it.
The plugin also sports the very latest SVN version of xAJAX 0.5 – its almost stable and wonderful to use – be sure you read the xAJAX site to note the differences in commands – we will not be implmenting legacy mode as we want to move forward fast! (The Joomla Plugin also doesnt require legacy mode!)
Please provide feedback in the Forum, not in the commenting below.
Sometimes you come across a problem so horrid that even google search only results in one link that talks about the problem. This post is titled Debugger compile handler overriden, cannot continue in the hope that google will index this post so other people having this error message of “Debugger compile handler overriden, cannot continue” will find this page and find the solution that has taken me over 2 hours to fix.
The problem:
When running Zend Studio Client and Zend Studio Server on the same windows PC and trying to install ionCube loaders as a Zend Extension you get the message “Debugger compile handler overriden, cannot continue” when trying to load a page. (This relates to Joomla as SEF advance needs ionCube and I need Zend Studio debugger to debug sites I am developing)
The Solution
To get rid of the error message “Debugger compile handler overriden, cannot continue” you need to edit the php.ini file. For zend that is normally in C:\Program Files\Zend\ZendStudioServer-5.1.0\etc\php.ini
In that file remove the line:
zend_debugger.expose_remotely=allowed_hosts
and restart apache – bingo! problem solved.
If this post has helped you please let me know using the comments section below.
Hi All.
FIRSTLY THERE IS NO KNOWN SECURITY HOLE IN JOOMLA TODAY – What I am saying here is JUST BECAUSE I want to be over cautious
Today my site was subject to some guy trying to use urls to gain access to my site and scripts.
The guy was using a well know method of accessing badly written scripts using a hacking script embedded in a fack image. You can see if you have been targeted by looking in your web logs for requests that include gif&cmd= and txt&cmd=
I am not going to post te exact method or how to use that to exploit unsecure scripts – (Joomla IS SECURE)
However we all have other scripts, including 3rd party Components, Modules and mambots that may have not been written to the great standard Joomla is. Therefore this patch is still extreamly helpful.
The following code can be inserted in any PHP script. However for Joomla I have inserted it in index.php and index2.php as those arethe files the hackers have been attempting to gain access through.
if (
ereg('gif\?cmd',$_SERVER['REQUEST_URI']) ||
ereg('gif&cmd',$_SERVER['REQUEST_URI']) ||
ereg('jpg\?cmd',$_SERVER['REQUEST_URI']) ||
ereg('jpg&cmd',$_SERVER['REQUEST_URI']) ||
ereg('txt?cmd',$_SERVER['REQUEST_URI']) ||
ereg('txt&cmd',$_SERVER['REQUEST_URI'])
)
{
// following line can be used to block IP Addresses if you use APF on a linus server
// passthru('apf -d '.$_SERVER['REMOTE_ADDR']);
$msg = "There was an hacking attempt by ".$_SERVER['REMOTE_ADDR']." trying to load ".$_SERVER['REQUEST_URI'];
mail('hacking@phil-taylor.com','HACKING ATTEMPT at '.$_SERVER['REQUEST_URI'],$msg);
die('Stop hacking!');
}
Im not saying this is perfect or even complete – however it suits my needs and I thought I would share it.