<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.0.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>Jelly and Custard</title>
	<link>http://www.jellyandcustard.com</link>
	<description>Web Development Blog</description>
	<pubDate>Fri, 28 Sep 2007 15:15:39 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.2</generator>
	<language>en</language>
			<item>
		<title>Creating Short URL&#039;s</title>
		<link>http://www.jellyandcustard.com/2007/09/28/creating-short-urls/</link>
		<comments>http://www.jellyandcustard.com/2007/09/28/creating-short-urls/#comments</comments>
		<pubDate>Fri, 28 Sep 2007 15:12:27 +0000</pubDate>
		<dc:creator>Khalid</dc:creator>
		
	<category>Other</category>
		<guid isPermaLink="false">http://www.jellyandcustard.com/2007/09/28/creating-short-urls/</guid>
		<description><![CDATA[I&#039;ve recently been involved in a project whereby we&#039;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&#8230; So we bought url.co.uk.
We decided [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://www.url.co.uk/'><img src="http://www.jellyandcustard.com/images/url.gif" alt="URL.co.uk" class='right' /></a>I&#039;ve recently been involved in a project whereby we&#039;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.</p>
<p>What we did this time round is get a really, <em><strong>really</strong></em> short url - something memorable too&#8230; So we bought <a href='http://www.url.co.uk/'>url.co.uk</a>.</p>
<p>We decided that we&#039;d start off by offering something &#039;new&#039; as well - where possible, we&#039;ll check the destination URL against a frequently updated database of known phishing sites. We don&#039;t want to send you and your visitors to a malicious site that looks like Paypal, but isn&#039;t Paypal!</p>
<p>We&#039;ve got more features in the pipeline, but I&#039;d urge you to give it a shot, and see what you think.</p>
<p>As always, I&#039;d appreciate any comments you have on the service!</p>
]]></content:encoded>
			<wfw:commentRSS>http://www.jellyandcustard.com/2007/09/28/creating-short-urls/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Pingdom - website monitoring</title>
		<link>http://www.jellyandcustard.com/2007/08/24/pingdom-website-monitoring/</link>
		<comments>http://www.jellyandcustard.com/2007/08/24/pingdom-website-monitoring/#comments</comments>
		<pubDate>Fri, 24 Aug 2007 14:36:16 +0000</pubDate>
		<dc:creator>Khalid</dc:creator>
		
	<category>Other</category>
		<guid isPermaLink="false">http://www.jellyandcustard.com/2007/08/24/pingdom-website-monitoring/</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>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 <a href="http://www.pingdom.com">their site</a> within the next 22 hours, using firefox, and sign up!
</p>
]]></content:encoded>
			<wfw:commentRSS>http://www.jellyandcustard.com/2007/08/24/pingdom-website-monitoring/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Finding the difference between dates</title>
		<link>http://www.jellyandcustard.com/2007/08/07/finding-the-difference-between-dates/</link>
		<comments>http://www.jellyandcustard.com/2007/08/07/finding-the-difference-between-dates/#comments</comments>
		<pubDate>Tue, 07 Aug 2007 14:48:19 +0000</pubDate>
		<dc:creator>Khalid</dc:creator>
		
	<category>PHP</category>
		<guid isPermaLink="false">http://www.jellyandcustard.com/2007/08/07/finding-the-difference-between-dates/</guid>
		<description><![CDATA[I needed a quick and easy to produce a human readable difference between two dates, and came up with the follwing:
PLAIN TEXT
PHP:




&#60;?php


function dateDiff&#40;$from,$to&#41; &#123;


&#160; $diff = $to - $from;


&#160; $info = array&#40;&#41;;


&#160; if&#40;$diff&#62;86400&#41; &#123;


&#160; &#160; //one or more days


&#160; &#160; $info&#91;'d'&#93; = &#40;$diff - &#40;$diff%86400&#41;&#41;/86400;


&#160; &#160; $diff = $diff%86400;


&#160; &#125;


&#160; if&#40;$diff&#62;3600&#41; &#123;


&#160; &#160; //one or [...]]]></description>
			<content:encoded><![CDATA[<p>I needed a quick and easy to produce a human readable difference between two dates, and came up with the follwing:</p>
<div class="igBar"><span id="lphp-3"><a href="#" onclick="javascript:showPlainTxt('php-3'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span><br />
<div id="php-3">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">function</span> dateDiff<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$from</span>,<span style="color:#0000FF;">$to</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#0000FF;">$diff</span> = <span style="color:#0000FF;">$to</span> - <span style="color:#0000FF;">$from</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#0000FF;">$info</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$diff</span>&gt;<span style="color:#CC66CC;color:#800000;">86400</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//one or more days</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$info</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'d'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$diff</span> - <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$diff</span>%<span style="color:#CC66CC;color:#800000;">86400</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>/<span style="color:#CC66CC;color:#800000;">86400</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$diff</span> = <span style="color:#0000FF;">$diff</span>%<span style="color:#CC66CC;color:#800000;">86400</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$diff</span>&gt;<span style="color:#CC66CC;color:#800000;">3600</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//one or more hours</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$info</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'h'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$diff</span> - <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$diff</span>%<span style="color:#CC66CC;color:#800000;">3600</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>/<span style="color:#CC66CC;color:#800000;">3600</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$diff</span> = <span style="color:#0000FF;">$diff</span>%<span style="color:#CC66CC;color:#800000;">3600</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$diff</span>&gt;<span style="color:#CC66CC;color:#800000;">60</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//one or more minutes</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$info</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'m'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$diff</span> - <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$diff</span>%<span style="color:#CC66CC;color:#800000;">60</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>/<span style="color:#CC66CC;color:#800000;">60</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$diff</span> = <span style="color:#0000FF;">$diff</span>%<span style="color:#CC66CC;color:#800000;">60</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$diff</span>&gt;<span style="color:#CC66CC;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$info</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'s'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#0000FF;">$diff</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#0000FF;">$f</span> = <span style="color:#FF0000;">''</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#616100;">foreach</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$info</span> <span style="color:#616100;">as</span> <span style="color:#0000FF;">$k</span>=&gt;<span style="color:#0000FF;">$v</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$v</span>&gt;<span style="color:#CC66CC;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#0000FF;">$f</span> .= <span style="color:#FF0000;">"$v $k, "</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#616100;">return</span> <a href="http://www.php.net/substr"><span style="color:#000066;">substr</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$f</span>,<span style="color:#CC66CC;color:#800000;">0</span>,-<span style="color:#CC66CC;color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Usage:</p>
<p>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. <strong>Tip:</strong> You can get the current timestamp by using <a href="http://www.php.net/time">time()</a>.</p>
<div class="igBar"><span id="lphp-4"><a href="#" onclick="javascript:showPlainTxt('php-4'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span><br />
<div id="php-4">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> dateDiff<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC66CC;color:#800000;">1186233948</span>,<span style="color:#CC66CC;color:#800000;">1186480322</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#FF9933; font-style:italic;">//2 d, 20 h, 26 m, 14 s</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> dateDiff<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC66CC;color:#800000;">1186233948</span>,<a href="http://www.php.net/time"><span style="color:#000066;">time</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#FF9933; font-style:italic;">//3 d, 1 h, 22 m, 7 s</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Enjoy!
</p>
]]></content:encoded>
			<wfw:commentRSS>http://www.jellyandcustard.com/2007/08/07/finding-the-difference-between-dates/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Email Attachments in PHP</title>
		<link>http://www.jellyandcustard.com/2007/04/28/email-attachments-in-php/</link>
		<comments>http://www.jellyandcustard.com/2007/04/28/email-attachments-in-php/#comments</comments>
		<pubDate>Sat, 28 Apr 2007 13:06:41 +0000</pubDate>
		<dc:creator>Khalid</dc:creator>
		
	<category>PHP</category>
		<guid isPermaLink="false">http://www.jellyandcustard.com/2007/04/28/email-attachments-in-php/</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>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.</p>
<p>However, there is a script around that makes this a lot easier by handling all the donkey work - <a href="http://phpmailer.sourceforge.net/">PHPMailer</a>. 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.</p>
<p>PHPMailer is a class based script, which means that you just need to include it into your PHP code, and fire it up:</p>
<div class="igBar"><span id="lphp-6"><a href="#" onclick="javascript:showPlainTxt('php-6'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span><br />
<div id="php-6">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">require</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"class.phpmailer.php"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$mail</span> = <span style="color:#000000; font-weight:bold;">new</span> phpmailer<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$mail</span>-&gt;<span style="color:#006600;">From</span> = <span style="color:#FF0000;">'me@mydomain.com'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$mail</span>-&gt;<span style="color:#006600;">FromName</span> = <span style="color:#FF0000;">"My Site's Name"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$mail</span>-&gt;<span style="color:#006600;">Subject</span> = <span style="color:#FF0000;">'Email Subject'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$mail</span>-&gt;<span style="color:#006600;">Body</span> = <span style="color:#FF0000;">"Here you can enter the body text for the email. </span></div>
</li>
<li style="font-weight: bold;color:#26536A;"></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">In fact it can:</span></div>
</li>
<li style="font-weight: bold;color:#26536A;"></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">&gt;Span </span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">&gt;Multiple Lines just like that!"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$mail</span>-&gt;<span style="color:#006600;">AddAddress</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"joe@brown.com"</span>,<span style="color:#FF0000;">"Joe Brown"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$mail</span>-&gt;<span style="color:#006600;">AddAttachment</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"./picture.jpg"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$mail</span>-&gt;<span style="color:#006600;">AddAttachment</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"./picture2.jpg"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$mail</span>-&gt;<span style="color:#006600;">Send</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>As you can see, we've set the From details up, as well as the subject and body text. We can then add the recipient address, the attachment, and then send. That's all there is to it!</p>
<p>You can keep adding attachments as shown above. Just ensure that you provide the right path to the files!
</p>
]]></content:encoded>
			<wfw:commentRSS>http://www.jellyandcustard.com/2007/04/28/email-attachments-in-php/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>httpOnly cookies in PHP</title>
		<link>http://www.jellyandcustard.com/2006/08/11/httponly-cookies-in-php/</link>
		<comments>http://www.jellyandcustard.com/2006/08/11/httponly-cookies-in-php/#comments</comments>
		<pubDate>Fri, 11 Aug 2006 09:52:02 +0000</pubDate>
		<dc:creator>Khalid</dc:creator>
		
	<category>PHP</category>
	<category>PHP 5</category>
		<guid isPermaLink="false">http://www.jellyandcustard.com/2006/08/11/httponly-cookies-in-php/</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://ilia.ws/archives/121-httpOnly-cookie-flag-support-in-PHP-5.2.html">Ilia</a>, one of the PHP developers, has included a patch by <a href="http://aspn.activestate.com/ASPN/Mail/Message/php-dev/3225088">Scott MacVicar</a> 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.</p>
<p>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.<br />
<div class="igBar"><span id="lphp-8"><a href="#" onclick="javascript:showPlainTxt('php-8'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span><br />
<div id="php-8">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/header"><span style="color:#000066;">header</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"Set-Cookie: hidden=value; httpOnly"</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>However, browser compatibility is not complete. It is available in MSIE, but is lacking in <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=178993">Mozilla</a>, <a href="http://weblogs.mozillazine.org/gerv/archives/2006/07/httponly_for_firefox.html">Firefox</a> and Safari. More discussion on the benefits of this cookie can be found on the <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=178993#c20">Mozilla Bugzilla</a>.</p>
<p>You can download PHP 5.2.-dev from the <a href="http://snaps.php.net/">PHP Website</a>. It however, has not yet been released as a public stable, so precaution is necessary for production servers.
</p>
]]></content:encoded>
			<wfw:commentRSS>http://www.jellyandcustard.com/2006/08/11/httponly-cookies-in-php/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>SQL Join syntax: Theta vs ANSI</title>
		<link>http://www.jellyandcustard.com/2006/08/10/sql-join-syntax-theta-vs-ansi/</link>
		<comments>http://www.jellyandcustard.com/2006/08/10/sql-join-syntax-theta-vs-ansi/#comments</comments>
		<pubDate>Thu, 10 Aug 2006 13:21:23 +0000</pubDate>
		<dc:creator>Khalid</dc:creator>
		
	<category>MySQL</category>
		<guid isPermaLink="false">http://www.jellyandcustard.com/2006/08/10/sql-join-syntax-theta-vs-ansi/</guid>
		<description><![CDATA[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).
Good database design should adhere to the third normal form, or "3NF". In a nutshell, relating bits [...]]]></description>
			<content:encoded><![CDATA[<p>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).</p>
<p>Good database design should adhere to the third normal form, or "3NF". In a nutshell, relating bits of data to other bits of data with minimal memory/storage overheads. In order to utilise a 3NF database effectively, table joins (linking and extracting data from two different internal sources) are an absolute must. In standard Structured Query Language syntax, there are two main join-types: <em>theta</em> and <em>ANSI</em>. Here's an example of each, using the common book/author database example:
<pre># This is a theta join example
SELECT
b.`title`,
CONCAT_WS(' ',a.`firstname`,a.`surname`) AS `author`
FROM
`books` b,  `authors` a
WHERE
b.`author_id` = a.`author_id`</pre>
<p>Here you can see that the table join takes place in the WHERE clause, so we only pull out records where the <em>books</em> table's <em>author_id</em> foreign key column matches the authors table's primary key of the same name.</p>
<p>The equivalent as an ANSI join is as follows:
<pre>SELECT
b.`title`,
CONCAT_WS(' ',a.`firstname`,a.`surname`) AS `author`
FROM
`books` b
INNER JOIN  # "INNER" is not required, however it is considered best practice
`authors` a ON b.`author_id` = a.`author_id`</pre>
<p>Like the theta example, this will pull out everything from <em>books</em>, where there's an author to go with it. Now suppose we haven't yet stored the author data for a given book, but we still want to extract a list of all of the books in our example - with an ANSI join is nice and easy, just swap the word INNER for LEFT, meaning that the left-hand table (<em>books</em>) takes precidence and does not depend upon there being a corresponding record (or set of) from the joined table.</p>
<p>So how would you replicate that with a theta join? Let's take a look:
<pre>SELECT
b.`title`,
CONCAT_WS(' ',a.`firstname`,a.`surname`) AS `author`
FROM
`books` b,
`authors` a
WHERE
b.`author_id` = a.`author_id`
OR a.`author_id` IS NULL</pre>
<p>Not as elegant, is it? It's also far easier to create accidental <a href="http://www.fluffycat.com/SQL/Cartesian-Joins/">cartesian joins</a>  using the theta method, which is not a good situation to be in, especially when your row count goes into the hundreds on either table - the result is very CPU/Memory hungry and can even bring a user's browser, and even a server, to a grinding halt. Theta style joins in general (and in my experience) are notably resource intenstive compared to ANSI equivalents.<br />
It's also worth noting that in versions of MySQL prior to 5.x, it was acceptible to mix join types, i.e. use theta and ANSI joins in one query, like so:
<pre>SELECT
b.`title`,
CONCAT_WS(' ',a.`firstname`,a.`surname`) AS `author`
FROM
`reading_list` rl,
`books` b
# Here's the ANSI join...
INNER JOIN
`authors` a ON b.`author_id` = a.`author_id`
# ...and here's the theta join
WHERE
rl.`book_id` = b.`book_id`</pre>
<p>I hope that it goes without saying that this is very bad programming practice; it's illogical use two different tools (simultaneously) to do the same job! So much so that the chaps at MySQL have opted to flat-out deny mixed join types in the same query.</p>
<p>For further reading, I can thoroughly recommend <a href="http://dev.mysql.com/tech-resources/articles/mysql-db-design-ch5.html">Jon Stephens/Chad Russels article on the subject</a>, taken from the book "<a href="http://www.amazon.co.uk/gp/product/1590593324">Beginning MySQL Database Design and Optimization: From Novice to Professional</a>"  (ISBN 1-59059-332-4).
</p>
]]></content:encoded>
			<wfw:commentRSS>http://www.jellyandcustard.com/2006/08/10/sql-join-syntax-theta-vs-ansi/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Odd and Even Numbers</title>
		<link>http://www.jellyandcustard.com/2006/07/13/odd-and-even-numbers/</link>
		<comments>http://www.jellyandcustard.com/2006/07/13/odd-and-even-numbers/#comments</comments>
		<pubDate>Thu, 13 Jul 2006 15:20:06 +0000</pubDate>
		<dc:creator>Khalid</dc:creator>
		
	<category>PHP</category>
		<guid isPermaLink="false">http://www.jellyandcustard.com/2006/07/13/odd-and-even-numbers/</guid>
		<description><![CDATA[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:
PLAIN [...]]]></description>
			<content:encoded><![CDATA[<p>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.</p>
<p>However, a quick look at the <a href="http://uk.php.net/manual/en/index.php">PHP Manual</a> showed a much easier way of determining whether a number is odd or even:</p>
<div class="igBar"><span id="lphp-10"><a href="#" onclick="javascript:showPlainTxt('php-10'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span><br />
<div id="php-10">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$status</span> = <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC66CC;color:#800000;">1</span> &amp; <span style="color:#0000FF;">$number</span><span style="color:#006600; font-weight:bold;">&#41;</span> ? <span style="color:#FF0000;">'Odd'</span> : <span style="color:#FF0000;">'Even'</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The '&amp;' sign represents the bitwise 'AND' operator, and the appropriate <a href="http://uk.php.net/manual/en/ref.math.php#35318">user comment</a> explains:</p>
<blockquote><p>
The reason the bitwise AND ("&#038;") 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.</p>
<p>So if you do a " 1 &#038; $num", it will return zero if the number is even (since xxxxxxx0 [the even number in binary] and 00000001 [the 1]) don't share any bits, and will return 1 if the number is odd (xxxxxx1 and 000001).
</p></blockquote>
<p>It's nice little tips like these found in PHP keeps me going throughout the day!
</p>
]]></content:encoded>
			<wfw:commentRSS>http://www.jellyandcustard.com/2006/07/13/odd-and-even-numbers/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Regular Expressions in PHP</title>
		<link>http://www.jellyandcustard.com/2006/06/13/regular-expressions-in-php/</link>
		<comments>http://www.jellyandcustard.com/2006/06/13/regular-expressions-in-php/#comments</comments>
		<pubDate>Tue, 13 Jun 2006 11:45:00 +0000</pubDate>
		<dc:creator>Khalid</dc:creator>
		
	<category>Input Validation</category>
		<guid isPermaLink="false">http://www.jellyandcustard.com/2006/06/13/regular-expressions-in-php/</guid>
		<description><![CDATA[A short tutorial that touches on the world of regular expressions, their uses and how to create them.]]></description>
			<content:encoded><![CDATA[<p>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!</p>
<h3>The Functions</h3>
<p>Before you can concoct a regular expression, you need to know how to use them and what all those 'weird characters' do. In <a href="http://uk2.php.net/manual/en/ref.pcre.php">PHP</a>, there are several POSIX-type regex functions, and the most common ones are:
<ul>
<li><a href="http://uk2.php.net/manual/en/function.preg-match.php">preg_match</a> / <a href="http://uk2.php.net/manual/en/function.preg-match-all.php">preg_match_all</a></li>
<li><a href="http://uk2.php.net/manual/en/function.preg-replace.php">preg_replace</a> (which we'll cover another day!)</li>
</ul>
<p>Rather than go on about how they all work, I think the best way is to show them in use with an example. Ignore the regular expression patterns for now, they will be explained in depth later!</p>
<h3>Phone Number Example</h3>
<h4>Matching with Regular Expressions</h4>
<p>Matching with regex can also be thought of as 'searching' or 'finding' with regex. You supply the pattern, and the preg_match* functions will deliver the goods. The beauty of the functions mean that the function will return true if a match is successfully made, and you can also optionally retrieve the 'found' contents by supplying a variable name as the third parameter, $matches in this case.</p>
<p>To demonstrate, lets take a look at the following. Our user has input their phone number, but we want to store the area code separately from the rest of the number. For the sake of arguments, lets assume the phone number is input as xxx xxx xxxx with the separator being either a space, a hyphen or nothing at all:</p>
<div class="igBar"><span id="lphp-11"><a href="#" onclick="javascript:showPlainTxt('php-11'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span><br />
<div id="php-11">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$var</span> = <span style="color:#FF0000;">'123-456-7890'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/preg_match"><span style="color:#000066;">preg_match</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"/^(<span style="color:#000099; font-weight:bold;">\</span>d{3})[<span style="color:#000099; font-weight:bold;">\</span>s-]?/"</span>,<span style="color:#0000FF;">$var</span>,<span style="color:#0000FF;">$matches</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#FF9933; font-style:italic;">//returns true</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/print_r"><span style="color:#000066;">print_r</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$matches</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>
$matches gives:<br />
<blockquote>
<pre>Array
(
    [0] => 123-
    [1] => 123
)</pre>
</blockquote>
<p>As you can see, we get a 'true' return from preg_match and our $matches variable contains the information matched by our expression, <strong>/^(\d{3})[\s-]?/</strong>. Regular expressions will match <strong>and return</strong> patterns surrounded in round brackets, as you can see in the above example with /^(<strong>\d{3}</strong>)[\s-]?/. The first element in the $matches array is always the entire result of the regex match. Subsequent matches are stored in the array in the order of the matching brackets in the regex.</p>
<p>The trick to dealing with regex patterns is to take it one character at a time. Looking at the above regex, lets dismantle it and take it piece by piece:</p>
<h4>Dismantling "/^(\d{3})[\s-]?/"</h4>
<table style="border: 0px; width: 450px;">
<tr>
<td>/</td>
<td> Forward Slashes are at the beginning and end of the actual expression, and define the expression - similar to how spaces define where a word starts and ends. You can use a multitude of characters instead of / such as | or @. If you need to use the character within your expression, then it has to be escaped with a backslash</td>
</tr>
<tr>
<td>^</td>
<td>The caret, ^, signifies the start of the string. This forces our regular expression to start from the beginning of our string. Within a character class, [...], the caret can signify, 'does not contain'. For example, [^a], means "does not contain 'a'"</td>
</tr>
<tr>
<td>( )</td>
<td>The curved brackets here signify a group matching. That is, whatever is matched by the expression within the brackets is returned to the user in the $matches array</td>
<tr>
<tr>
<td>\d</td>
<td>The \d is a special character class meaning 'match all digits'. It is identical to [0-9] but easier to write. This will match all digits found but will not match letters, punctuation etc</td>
</tr>
<tr>
<td>{3}</td>
<td>The number 3 surrounded by curly brackets signified the number of times the previous expression must match. In this case, it means that \d should be matched three times - so it will match 123 but not just 12. </td>
</tr>
<tr>
<td>[\s-]?</td>
<td>This character class will match one of the characters in the square brackets. In this case, its either s which represents a space character, and a hyphen to match a hyphen. The question mark at the end means 'Match 0 or 1 times', meaning that there can only be a space, or a hyphen or neither.</td>
</tr>
<tr>
<td>/</td>
<td>The final slash represents the end of our expression</td>
</tr>
</table>
<p>As you can see, when you break up the regular expression, things do appear more simple. We've covered a lot in the above expression, and so I will try to elaborate a bit more below.</p>
<h3>Anchors</h3>
<p>There are only two anchors I want to bring into the equation for now:</p>
<p>^ - will match the beginning of a line/string <strong>when</strong> it is not present in a [...] character class.<br />
$ - will match the end of a line/string</p>
<h3>Character Classes</h3>
<p>There are two sorts of character classes. One's within square brackets, and others that are shorthand, like \d above. Within square brackets, you can list characters that you want to be accepted or rejected:</p>
<p>[abc] - will match a or b or c<br />
[^abc] - will match anything BUT a or b or c - i.e. any character that is not a or b or c</p>
<p>You can include ranged of information:</p>
<p>[a-zA-Z] - will match a-z letters in both upper and lower case<br />
[0-9] - will match digits 0-9</p>
<p>If you want to match a hyphen, then you need to have the hyphen as the last character:</p>
<p>[a-z-] - will match a-z in lowercase only, and hyphens</p>
<p>There are other character classes that are shorthand:</p>
<p>\s - matches whitespace characters: n, r (both new lines), t (tabs) and f (form feeds - not use often). Equivalent to [nrtf]<br />
\S - matches all non-whitespace characters. Equivalent to [^nrtf]<br />
\d - matches 0-9. Equivalent to [0-9]<br />
\D - matches all non-digits. Equivalent to [^0-9]<br />
\w - matches a word character: a-z, A-Z and 0-9. Equivalent to [a-zA-Z0-9]<br />
\W - matches all non-word characters. Equivalent to [^a-zA-Z0-9]<br />
. - the period matches any character apart from new lines. If you wish to match an actual period, you need to escape it using a backslash: \.</p>
<h3>Ranges</h3>
<p>As we saw above with {3} you can specify the number of times you wish to match the previous expression. Above we used \d{3} but we could have easily used \d\d\d - but using a range is a lot more neater, and readable.</p>
<p>However, a range can be as you'd expect: a range from x through to y. For example, {3,5} means that the previous expression must be matched at least 3 times and at most 5 times. So for:</p>
<p>preg_match("/\d{3,5}/",$var);</p>
<p>we will get a true return from preg_match() if $var ranges from 100 through to 99999.</p>
<p>Now, what if you want $var to range from 100 until infinity? This can be done by not providing a second digit in the range: {3,} - will match <em>at least</em> three digits.</p>
<p>Ranges are simple, and can be a great help</p>
<h3>Wildcards</h3>
<p>The last thing I want to discuss are expression wildcards. There are three wildcards that are used regularly:</p>
<p>? - The question mark will match the preceeding expression 0 or 1 times. This is very handy for when you want the input to have an optional character. We used this above to account for a hyphen, space or nothing as our separator in the phone number<br />
+ - A plus sign will match the preceeding expression 1 or more times. This is useful for when you require something to be present.<br />
* - An asterisk wildcard will match the preceeding expression 0 or more times. There is an unlimited times that it will match. For example, .* will match every character in a line.</p>
<h3>A final example</h3>
<p>Using the information we have above, let's create a regular expression that will match a hex colour that will end up in a CSS stylesheet. Hex colours have 6 characters that range from 0-9 or A-F. To check this using a regular expression, we need to start at the beginning of our string, so we start with a ^. We want to check for a # sign so we add that to our expression so far:</p>
<p>/^#/</p>
<p>We now need to add the juicy bit, which is checking for A-F, a-f and 0-9 only 6 characters allowed from that list:</p>
<p>/^#[a-fA-F0-9]{6}/</p>
<p>We finish the expression by ensuring we are checking the entire string. We can do this by using the end of line character, $. This, combined with ^ means we check from the beginning of the input through to the end of the input, and the only characters allowed are those in our expression. This gives our final expression:</p>
<p>/^#[a-fA-F0-9]{6}$/</p>
<p>This has been a whistle-stop tour of basic regular expression. There is a lot more that can be done, and a lot that I have missed out for the sake of simplicity. Keep an eye out for a follow up explaining more of the world of regular expressions.
</p>
]]></content:encoded>
			<wfw:commentRSS>http://www.jellyandcustard.com/2006/06/13/regular-expressions-in-php/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Determining if a URL exists with Curl</title>
		<link>http://www.jellyandcustard.com/2006/05/31/determining-if-a-url-exists-with-curl/</link>
		<comments>http://www.jellyandcustard.com/2006/05/31/determining-if-a-url-exists-with-curl/#comments</comments>
		<pubDate>Wed, 31 May 2006 13:07:24 +0000</pubDate>
		<dc:creator>Khalid</dc:creator>
		
	<category>PHP</category>
		<guid isPermaLink="false">http://www.jellyandcustard.com/2006/05/31/determining-if-a-url-exists-with-curl/</guid>
		<description><![CDATA[Checking whether a URL actually exists by using the HTTP Code returned when requesting that page in PHP.]]></description>
			<content:encoded><![CDATA[<p>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.</p>
<p>Luckily, this is quite easy if you have the <a href="http://uk.php.net/curl">Curl</a> extension installed.</p>
<h3>Using Curl in PHP</h3>
<p><a href="http://curl.haxx.se/">Curl</a> is a collection of client URL library functions that we can use to perform a multitude of URL related activities. You can send a POST or file upload to a URL, use it as a proxy, send/receive XML requests, and much <a href="http://www.jellyandcustard.com/2006/01/02/php-curl-http-put-ssl-and-basic-authentication/">more</a>. In fact, there are over 100 <a href="http://uk.php.net/manual/en/function.curl-setopt.php">configuration</a> options that can customise this to your needs.</p>
<p>Still, for this tutorial, all we want is to check that a URL exists. We can do this by using curl to grab the headers when requesting the URL and check the Status: header returned.</p>
<div class="igBar"><span id="lphp-12"><a href="#" onclick="javascript:showPlainTxt('php-12'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span><br />
<div id="php-12">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$ch</span> = curl_init<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">curl_setopt<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span>, CURLOPT_URL, <span style="color:#FF0000;">"http://www.jellyandcustard.com/"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">curl_setopt<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span>, CURLOPT_HEADER, <span style="color:#000000; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">curl_setopt<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span>, CURLOPT_NOBODY, <span style="color:#000000; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">curl_setopt<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span>, CURLOPT_RETURNTRANSFER, <span style="color:#000000; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$data</span> = curl_exec<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">curl_close<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$data</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The result from running the above code is:<br />
<blockquote>
HTTP/1.1 200 OK<br />
Date: Wed, 31 May 2006 12:25:26 GMT<br />
Server: Apache<br />
X-Powered-By: PHP/5.1.2<br />
X-Pingback: http://www.jellyandcustard.com/xmlrpc.php<br />
Status: 200 OK<br />
Content-Type: text/html; charset=UTF-8
</p></blockquote>
<p>As you can see, we have our Status: 200 OK HTTP Code which means the page exists. If we get a 404 HTTP code then the page doesn't exist. A list of HTTP Codes can be found at <a href="http://en.wikipedia.org/wiki/List_of_HTTP_status_codes">Wikipedia</a>.</p>
<p>If the domain can't be resolved, then $data will return false, which we can check against with a simple if() statement.</p>
<p>In order to utilise the information returned, we need to use a regular expression to grab the HTTP code, and then based upon that, we can let the user know our results:<br />
<div class="igBar"><span id="lphp-13"><a href="#" onclick="javascript:showPlainTxt('php-13'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span><br />
<div id="php-13">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/preg_match"><span style="color:#000066;">preg_match</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"/HTTP<span style="color:#000099; font-weight:bold;">\</span>/1<span style="color:#000099; font-weight:bold;">\</span>.[1|0]<span style="color:#000099; font-weight:bold;">\</span>s(<span style="color:#000099; font-weight:bold;">\</span>d{3})/"</span>,<span style="color:#0000FF;">$data</span>,<span style="color:#0000FF;">$matches</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/print_r"><span style="color:#000066;">print_r</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$matches</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<blockquote><pre>
Array
(
    [0] => Status: 200
    [1] => 200
)
</pre>
</blockquote>
<p>So $matches[1] has our error code. If this matches 200 then the page exists, and if it is 404, then our page doesn't exist.</p>
<p>A slight change has to be made for pages that use a <a href="http://www.jellyandcustard.com/2006/05/24/subdomain-link-cloaking/">301/302/307 redirect</a>. We need to instruct Curl to follow the redirect, and report what's found. These redirects produce a lot of headers, as seen when testing http://ukdomains.jellyandcustard.com:<br />
<div class="igBar"><span id="lphp-14"><a href="#" onclick="javascript:showPlainTxt('php-14'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span><br />
<div id="php-14">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$ch</span> = curl_init<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">curl_setopt<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span>, CURLOPT_URL, <span style="color:#FF0000;">"http://ukdomains.jellyandcustard.com/"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">curl_setopt<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span>, CURLOPT_HEADER, <span style="color:#000000; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">curl_setopt<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span>, CURLOPT_NOBODY, <span style="color:#000000; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">curl_setopt<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span>, CURLOPT_RETURNTRANSFER, <span style="color:#000000; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">curl_setopt<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span>, CURLOPT_FOLLOWLOCATION, <span style="color:#000000; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">curl_setopt<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span>, CURLOPT_MAXREDIRS, <span style="color:#CC66CC;color:#800000;">10</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#FF9933; font-style:italic;">//follow up to 10 redirections - avoids loops</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$data</span> = curl_exec<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">curl_close<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$data</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/preg_match_all"><span style="color:#000066;">preg_match_all</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"/HTTP<span style="color:#000099; font-weight:bold;">\</span>/1<span style="color:#000099; font-weight:bold;">\</span>.[1|0]<span style="color:#000099; font-weight:bold;">\</span>s(<span style="color:#000099; font-weight:bold;">\</span>d{3})/"</span>,<span style="color:#0000FF;">$data</span>,<span style="color:#0000FF;">$matches</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/print_r"><span style="color:#000066;">print_r</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$matches</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<blockquote><p>
HTTP/1.1 302 Found<br />
Date: Wed, 31 May 2006 12:50:38 GMT<br />
Server: Apache<br />
Location: http://www.123-reg.co.uk/affiliate.cgi?id=AF106554<br />
Content-Type: text/html; charset=iso-8859-1</p>
<p>HTTP/1.1 302 Found<br />
Date: Wed, 31 May 2006 12:50:42 GMT<br />
Server: Apache/2.0.53<br />
URL: http://www.123-reg.co.uk/<br />
Set-Cookie: 123reg_affiliate=106554-92bab777b0ae96c938107985db7a98e4; path=/secure/; expires=Sat, 28-May-2016 12:50:43 GMT; secure<br />
Location: http://www.123-reg.co.uk/<br />
Content-Type: text/html; charset=iso-8859-1</p>
<p>HTTP/1.1 200 OK<br />
Date: Wed, 31 May 2006 12:50:43 GMT<br />
Server: Apache/2.0.53<br />
Accept-Ranges: bytes<br />
Content-Length: 33854<br />
Content-Type: text/html
<pre>
Array
(
    [0] => Array
        (
            [0] => HTTP/1.1 302
            [1] => HTTP/1.1 302
            [2] => HTTP/1.1 200
        )

    [1] => Array
        (
            [0] => 302
            [1] => 302
            [2] => 200
        )

)</pre>
</blockquote>
<p>Our Status code can be found by:</p>
<div class="igBar"><span id="lphp-15"><a href="#" onclick="javascript:showPlainTxt('php-15'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span><br />
<div id="php-15">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$code</span> = <a href="http://www.php.net/end"><span style="color:#000066;">end</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$matches</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#CC66CC;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Which we can now check for 200 or 404 etc to make sure that you've been given a real URL, and not one that is made up. So the entire code all together:</p>
<div class="igBar"><span id="lphp-16"><a href="#" onclick="javascript:showPlainTxt('php-16'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span><br />
<div id="php-16">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$ch</span> = curl_init<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">curl_setopt<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span>, CURLOPT_URL, <span style="color:#FF0000;">"http://www.jellyandcustard.com/"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">curl_setopt<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span>, CURLOPT_HEADER, <span style="color:#000000; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">curl_setopt<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span>, CURLOPT_NOBODY, <span style="color:#000000; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">curl_setopt<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span>, CURLOPT_RETURNTRANSFER, <span style="color:#000000; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">curl_setopt<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span>, CURLOPT_FOLLOWLOCATION, <span style="color:#000000; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">curl_setopt<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span>, CURLOPT_MAXREDIRS, <span style="color:#CC66CC;color:#800000;">10</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#FF9933; font-style:italic;">//follow up to 10 redirections - avoids loops</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$data</span> = curl_exec<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">curl_close<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/preg_match_all"><span style="color:#000066;">preg_match_all</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"/HTTP<span style="color:#000099; font-weight:bold;">\</span>/1<span style="color:#000099; font-weight:bold;">\</span>.[1|0]<span style="color:#000099; font-weight:bold;">\</span>s(<span style="color:#000099; font-weight:bold;">\</span>d{3})/"</span>,<span style="color:#0000FF;">$data</span>,<span style="color:#0000FF;">$matches</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$code</span> = <a href="http://www.php.net/end"><span style="color:#000066;">end</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$matches</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#CC66CC;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span>!<span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"Domain could not be found"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">else</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$code</span>==<span style="color:#CC66CC;color:#800000;">200</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"Page Found"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">elseif</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$code</span>==<span style="color:#CC66CC;color:#800000;">404</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"Page Not Found"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Enjoy!
</p>
]]></content:encoded>
			<wfw:commentRSS>http://www.jellyandcustard.com/2006/05/31/determining-if-a-url-exists-with-curl/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Subdomain Link Cloaking</title>
		<link>http://www.jellyandcustard.com/2006/05/24/subdomain-link-cloaking/</link>
		<comments>http://www.jellyandcustard.com/2006/05/24/subdomain-link-cloaking/#comments</comments>
		<pubDate>Wed, 24 May 2006 14:29:33 +0000</pubDate>
		<dc:creator>Khalid</dc:creator>
		
	<category>Apache</category>
		<guid isPermaLink="false">http://www.jellyandcustard.com/2006/05/24/subdomain-link-cloaking/</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>A common practice at the moment is to shorten affiliate links into a more useable format. For example, I have an affiliate link for <a href="http://www.123-reg.co.uk/affiliate.cgi?id=AF106554">123-reg.co.uk</a> which is <a href="http://www.123-reg.co.uk/affiliate.cgi?id=AF106554">http://www.123-reg.co.uk/affiliate.cgi?id=AF106554</a>. 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.</p>
<p>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:</p>
<ol>
<li>First up, you need to be able to accept all traffic to your domain's subdomains. You need to create a wildcard DNS record for your subdomains - in this case *.jellyandcustard.com. If you have no idea how to do this, then the best step is to contact your webhost, who will be able to assist you.</li>
<li>Second up is to let your webserver know that you are accepting all traffic for your subdomains. This can be done in your apache httpd.conf by adding <code>ServerAlias *.domain.com</code> to your site's Virtual Host. If you do not have root access to your webserver, chances are you will have to get your host to add this in.</li>
<li>Finally, once this is done, you can start utilising the subdomains by using mod_rewrite in a .htaccess file. Here's what I've done for ukdomains.jellyandcustard.com:<br />
<blockquote>
RewriteEngine On</p>
<p>RewriteCond %{HTTP_HOST} ^ukdomains.jellyandcustard.com$ [NC]<br />
RewriteRule ^(.*)$ http://www.123-reg.co.uk/affiliate.cgi?id=AF106554 [L,R=302]</p></blockquote>
</li>
</ol>
<p>Simply rinse and repeat for any other domains that you need. Wonder if it actually works? Give it a <a href="http://ukdomains.jellyandcustard.com">try</a>! You do not need to repeat the <code>RewriteEngine On</code> line once it has already been added.
</p>
]]></content:encoded>
			<wfw:commentRSS>http://www.jellyandcustard.com/2006/05/24/subdomain-link-cloaking/feed/</wfw:commentRSS>
		</item>
	</channel>
</rss>
