PHP Subtract Dates
The following function will return the number of days between two dates.
function dateDiff($beginDate, $endDate) {
$fromDate = date('Y-n-j',strtotime($beginDate));
$toDate = date('Y-n-j',strtotime($endDate));
$date_parts1=explode('-', $beginDate);
$date_parts2=explode('-', $endDate);
$start_date=gregoriantojd($date_parts1[1], $date_parts1[2], $date_parts1[0]);
$end_date=gregoriantojd($date_parts2[1], $date_parts2[2], $date_parts2[0]);
return $end_date - $start_date;
}
// example $from = '2011-1-6'; $to = '2011-1-8'; dateDiff($from,$to); // returns 2
Turn off IPv6 CentOS and CSF
If you are running csf on your CentOS server and run the server security check you may have seen the following message:
Check for IPv6: IPv6 appears to be enabled [ifconfig: ]. If ip6tables is installed, you should enable the csf IPv6 firewall (IPV6 in csf.conf). To disable IPv6 on RHEL/CentOS you should follow this link.
Upon following the link you end up at the login screen for access.redhat.com. Even after creating an account viewing the link requires a subscription. Seems a little odd that a subscription is required to find out how to disable IPv6…
So, here is how you do it:
- Log into the server as root
- Type in the following:
# touch /etc/modprobe.d/disable-ipv6 # echo "options ipv6 disable=1" >> /etc/modprobe.d/disable-ipv6
Note: Slightly different prior to the 5.4 update. For more information on the above see this link on the centos wiki. Its a bit more helpful than the link provided in the csf notes.
- Restart the server
jQuery Tutorials
Been brushing up on my jQuery. Here are some GREAT tutorials that take things from scratch…
USB Drive Autorun
I have been hunting for a good way to get a USB Flash Drive to autorun when inserted into a computer. The ideal solution would work just as a CD’s autorun (ie work with all versions of Windows and MacOS). Given my time constraint I was only able to locate a solution that works 100% with Windows Vista.
If anyone has a link to the Holy Grail of USB Flash Drive Autorun please comment below :)
Here is what I used
(used it to autorun a Flash Windows Projector file):
Create an Autorun.inf file and place it at the root of your flash drive along with your program files.
[AutoRun] OPEN=YourProgram.exe ICON=YourProgramFileWithIcon.exe ACTION=Message that is displayed LABEL=Drive Label
Here is the link where most the info I used was found.
Changing back to default permissions
When modifying file permissions it is sometimes necessary to go back to the drawing board and set back to the default permissions. The following command can be used via ssh and takes a couple seconds vs trying to do this via ftp file by file (which can take a very long time depending on the size of your website)
Change to the directory you want changed, then run these;
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
Will set permission for all files to 644 and all directories to 755.
This works for pretty much any Linux server.
Finally, how to set SpamAssasin!
I proudly battle against spam on behalf of my clients! Running PLESK and SpamAssassin, it takes a lot of tweaks to make sure the mystery meat doesn’t get through. I recently came across the following and am currently testing it out. So far, its looking good!
Originally posted at www.jaguarpc.com by thisisit3
Transfer Horde emails to a new server
We use Horde as one of the webmail solutions on our servers ( also using RoundCube and SquirrelMail ). Occasionally it becomes necessary to move the emails saved on the server to a new server or email account. This can easily be done with the Linux/Unix scp (secure copy) command.
Read more
Changing the name of Horde

If you use Horde 3 as the webmail client for your clients you may want to customize the name of the login page to something more friendly to your business. You can do so by editing the ‘registry.php’ file in your configuration directory (on most my servers located at /etc/psa-horde/horde/). Toward the bottom you will find:
$this->applications['horde'] = array(
'fileroot' => '/usr/share/psa-horde',
'webroot' => $webroot,
'initial_page' => 'login.php',
'name' => _("Horde"),
'status' => 'active',
'templates' => '/usr/share/psa-horde/templates',
'provides' => 'horde'
);
Change (“Horde”) to (“WhateverYouWant”). For me I changed it to (“DynamicMail”) seen below.
(Note: as of January 2010 Horde is no longer called DynamicMail on our servers)
Default Horde Theme
If you would like have a different default theme other than the ‘Blue and White’ theme that ships with Horde 3 you can easily do so by editing the prefs.php located in the Horde conf-directory (on most my servers it is located at /etc/psa-horde/horde/). About 2/3rds of the way down in the file you will find:
// UI theme
$_prefs['theme'] = array(
'value' => 'bluewhite',
'locked' => false,
'shared' => true,
'type' => 'select',
'desc' => _("Select your color scheme.")
);
Change ‘bluewhite’ to the directory name of the theme you would like to use as the default. A great theme I use that does not ship with Horde is WPS Sober found here (read the README.txt in the download for installation directions). If you go with the WPS Sober you would change ‘bluewhite’ to ‘wps_sober’ after installing the theme.
Enjoy!
Best Practices for Coding HTML Emails
If you are a web designer you know the pains of cross-browser coding. We currently have 3-4 popular browsers (IE6, IE7, FF, Safari) to keep in mind when creating new pages and each will interpret your code slightly different. This is the source of much hair pulling in the design community. However, shortly after delving into coding HTML emails, testing with 3-4 platforms starts looking inviting. Let me explain…
There are a wide range of tools available for viewing email; from software applications like Outlook, AOL, Lotus Notes, Eudora, etc. to web applications like Yahoo Mail, Google Mail, Hotmail and others. Each one of these has the potential of rendering your code differently and all have to be taken into account when coding your emails. So if you have any hair left, here are some ‘best practices’ you can follow to help keep your end users’ experience as uniform as possible.