I've recently been involved in a project whereby we'll convert a long URL into a short URL. This is by no means a new service - some sites have been doing this for ages.
What we did this time round is get a really, really short url - something memorable too… So we bought url.co.uk.
We decided that we'd start off by offering something 'new' as well - where possible, we'll check the destination URL against a frequently updated database of known phishing sites. We don't want to send you and your visitors to a malicious site that looks like Paypal, but isn't Paypal!
Read the full article (138 words & 1 image)
September 28th, 2007
Just a heads up to those of you who are interested in monitoring your site uptime. Pingdom are celebrating the release of their firefox extension by giving away free one year subscriptions to their service (normally $120/year). All you need to do is visit their site within the next 22 hours, using firefox, and sign up!
August 24th, 2007
I needed a quick and easy to produce a human readable difference between two dates, and came up with the follwing:
PHP:
-
<?php
-
function dateDiff($from,$to) {
-
$diff = $to - $from;
-
-
if($diff>86400) {
-
//one or more days
-
$info['d'] = ($diff - ($diff%86400))/86400;
-
$diff = $diff%86400;
-
}
-
if($diff>3600) {
-
//one or more hours
-
$info['h'] = ($diff - ($diff%3600))/3600;
-
$diff = $diff%3600;
-
}
-
if($diff>60) {
-
//one or more minutes
-
$info['m'] = ($diff - ($diff%60))/60;
-
$diff = $diff%60;
-
}
-
if($diff>0) {
-
$info['s'] = $diff;
-
}
-
$f = '';
-
foreach($info as $k=>$v) {
-
if($v>0) $f .= "$v $k, ";
-
}
-
-
}
-
?>
Usage:
Just ensure that you pass it two timestamps, the first one being the date FROM when you want to calculate, the second one being where you want it calculated TO. Tip: You can get the current timestamp by using time().
PHP:
-
<?php
-
echo dateDiff
(1186233948,
1186480322);
//2 d, 20 h, 26 m, 14 s
-
echo dateDiff
(1186233948,
time());
//3 d, 1 h, 22 m, 7 s
-
?>
Enjoy!
August 7th, 2007
I've often been asked how to not just send emails from PHP, but how to send an attachment within the email as well. To send an attachment, you need to add extra headers, base64 encode the file and so on. In fact, it's not very easy to do.
However, there is a script around that makes this a lot easier by handling all the donkey work - PHPMailer. PHPMailer can handle almost anything you want to throw at it, including embedding images within the email, full blown HTML emails, using external SMTP servers to send the emails and so on. However, today, we're going to just concentrate on using PHPMailer to send an email with an attachment.
April 28th, 2007
Ilia, one of the PHP developers, has included a patch by Scott MacVicar into CVS for PHP 5.2 that allows you to set a httpOnly cookie instead of a normal cookie. A httpOnly cookie allows you to set a cookie that isn't accessible via Javascript, and so removes the possibility of some nefarious code to try and read your cookie.
This can be enabled in PHP 5.2. by passing TRUE as the 7th paramenter in setcookie() and setrawcookie(). In versions below 5.2, you can set this by passing an additional header.
PHP:
-
header("Set-Cookie: hidden=value; httpOnly");
August 11th, 2006
At the heart of every dynamic website is some form of data source, whether it's a simple flat text file, XML schema, or full blown database. In this article, I'll be addressing database table joins with SQL (specifically MySQL).
August 10th, 2006
Sometimes its necessary to find out whether a number is odd or even. When I initially hit upon the problem, my immediate thought was to use the modulus function % and inspect the result.
However, a quick look at the PHP Manual showed a much easier way of determining whether a number is odd or even:
PHP:
-
$status = (1 & $number) ? 'Odd' : 'Even';
The '&' sign represents the bitwise 'AND' operator, and the appropriate user comment explains:
The reason the bitwise AND ("&") operator works to determine whether a number is odd or even is because odd numbers expressed in binary always have the rightmost (2^0) bit = 1 and even numbers always have the 2^0 bit = 0.
July 13th, 2006
Regular Expressions (regex for short) appear to a lot of people as the 'black art' of coding. Most languages, be it PHP, Java, C, .NET, VB etc have a way of using regular expressions - and they can certainly make your job easier. So lets start on our journey into regular expressions. I am by no means an expert, but hopefully I'll be able to clear the fog that surrounds regular expressions!
Continue Reading June 13th, 2006
Its quite common for people to enter in their URL when signing up - but what if you want to verify that this is a real page? You can validate the URL using a regular expression up to a point, but all that tells us is that the URL is well formed. What I wanted to do was to check that the page exists - i.e. that we don't get a 404 for it.
Luckily, this is quite easy if you have the Curl extension installed.
Continue Reading May 31st, 2006
A common practice at the moment is to shorten affiliate links into a more useable format. For example, I have an affiliate link for 123-reg.co.uk which is http://www.123-reg.co.uk/affiliate.cgi?id=AF106554. However, if I want to share that link with someone, I have to login to my control panel, and get the link. It would be a lot nicer if I could offer a more memorable link like ukdomains.jellyandcustard.com.
This is in fact very easy to set up, however for those of you on shared hosts (without access to httpd.conf) your host will need to aid you in one or two steps.Here's how I did it:
May 24th, 2006
Previous Posts