<?xml version="1.0" encoding="UTF-8"?>
<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/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>boolean.co.nz &#187; PHP</title>
	<atom:link href="http://boolean.co.nz/blog/category/development/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://boolean.co.nz/blog</link>
	<description>Where there is more to logic than TRUE or FALSE</description>
	<lastBuildDate>Sun, 29 Jan 2012 03:16:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Obtain Facebook likes via PHP SDK</title>
		<link>http://boolean.co.nz/blog/facebook-likes-sdk/713/</link>
		<comments>http://boolean.co.nz/blog/facebook-likes-sdk/713/#comments</comments>
		<pubDate>Sun, 29 Jan 2012 03:11:36 +0000</pubDate>
		<dc:creator>Boolean</dc:creator>
				<category><![CDATA[FaceBook]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://boolean.co.nz/blog/?p=713</guid>
		<description><![CDATA[In an update to this post here is another way to obtain the number of likes for a Facebook page. I&#8217;ll assume that you&#8217;ve already registered a Facebook application, have downloaded the PHP SDK and have included for use in your code. require(&#8216;facebook.php&#8217;); Setup an array with your Facebook applications credentials $facebook = new Facebook(array( [...]]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td><img src="http://boolean.co.nz/blog/wp-content/uploads/2009/03/php-logo.png" alt="" title="php-logo" width="203" height="107" class="aligncenter size-full wp-image-61" /></td>
</tr>
</table>
<p>In an update to this <a href="http://boolean.co.nz/blog/get-facebook-likes-and-shares-via-graph-api/626/" title="post" target="_blank">post</a> here is another way to obtain the number of likes for a Facebook page.</p>
<p>I&#8217;ll assume that you&#8217;ve already registered a Facebook application, have downloaded the PHP SDK and have included for use in your code.</p>
<div class="codesnip-container" >require(&#8216;facebook.php&#8217;);</div>
<p>Setup an array with your Facebook applications credentials</p>
<div class="codesnip-container" >$facebook = new Facebook(array(<br />
&#8216;appId&#8217; => &#8217;000000000&#8242;, // Put appID here<br />
&#8216;secret&#8217; => &#8217;0000c000c000c000c&#8217;, // Put your secret key here<br />
));</div>
<p>Decide which page you wish to obtain the number of likes for</p>
<div class="codesnip-container" >$getRequest = $facebook->api(&#8216;/cocacola&#8217;); // Lets look at the Facebook page for the popular soft drink<br />
echo $getRequests['likes'];</div>
<p>Obviously you can consume, contrast and display this information in more exciting ways than simply echoing it to the screen. Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://boolean.co.nz/blog/facebook-likes-sdk/713/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use PHP to display Gravatar images</title>
		<link>http://boolean.co.nz/blog/use-php-to-display-gravatar-images/668/</link>
		<comments>http://boolean.co.nz/blog/use-php-to-display-gravatar-images/668/#comments</comments>
		<pubDate>Fri, 14 Oct 2011 03:34:25 +0000</pubDate>
		<dc:creator>Boolean</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://boolean.co.nz/blog/?p=668</guid>
		<description><![CDATA[All URLs on Gravatar are based on the use of the hashed value of an email address. According to their best practice you should: Trim leading and trailing whitespace from an email address Force all characters to lower-case md5 hash the final string Of course in PHP this is trivial as the following function shows: [...]]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td><img src="http://boolean.co.nz/blog/wp-content/uploads/2009/03/php-logo.png" alt="" title="php-logo" width="203" height="107" class="aligncenter size-full wp-image-61" /></td>
</tr>
</table>
<p>All URLs on <a href="http://en.gravatar.com/site/implement/hash/" target="_blank">Gravatar</a> are based on the use of the hashed value of an email address. According to their best practice you should:</p>
<ol>
<li>Trim leading and trailing whitespace from an email address</li>
<li>Force all characters to lower-case</li>
<li>md5 hash the final string</li>
</ol>
<p>Of course in PHP this is trivial as the following function shows:</p>
<div class="codesnip-container" >function fetchGravatar() {<br />
$fetchHash = md5(strtolower(trim(&#8216;your_email.address.com&#8217;)));<br />
$GravatarImage = &#8216;http://www.gravatar.com/avatar/&#8217; . $fetchHash;<br />
return $GravatarImage;<br />
}</div>
<p><a href="http://en.gravatar.com/site/implement/profiles/" target="_blank">Profiles</a> are also available if you require them.</p>
]]></content:encoded>
			<wfw:commentRss>http://boolean.co.nz/blog/use-php-to-display-gravatar-images/668/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Host Settings Without phpinfo()</title>
		<link>http://boolean.co.nz/blog/php-host-settings-without-phpinfo/652/</link>
		<comments>http://boolean.co.nz/blog/php-host-settings-without-phpinfo/652/#comments</comments>
		<pubDate>Wed, 05 Oct 2011 09:36:05 +0000</pubDate>
		<dc:creator>Boolean</dc:creator>
				<category><![CDATA[Hosting]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://boolean.co.nz/blog/?p=652</guid>
		<description><![CDATA[Occasionally a webhost will block the very useful phpinfo() command making it difficult to understand any limitations of the server configuration. This script can display relevant information to help you understand what is happening behind the scenes. &#60;?php $d_func = ini_get(&#8220;disable_functions&#8221;); $up_max = ini_get(&#8220;upload_max_filesize&#8221;); $up_max = str_replace(&#8220;M&#8221;,&#8221;",$up_max); $up_max_size = &#8220;Megabytes&#8221;; $post_max = ini_get(&#8220;post_max_size&#8221;); $post_max = [...]]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td><img src="http://boolean.co.nz/blog/wp-content/uploads/2009/03/php-logo.png" alt="" title="php-logo" width="203" height="107" class="aligncenter size-full wp-image-61" />
<td>
<tr></table>
<p>Occasionally a webhost will block the very useful phpinfo() command making it difficult to understand any limitations of the server configuration. This script can display relevant information to help you understand what is happening behind the scenes.</p>
<div class="codesnip-container" >&lt;?php<br />
        $d_func = ini_get(&#8220;disable_functions&#8221;);<br />
        $up_max =  ini_get(&#8220;upload_max_filesize&#8221;);<br />
        $up_max = str_replace(&#8220;M&#8221;,&#8221;",$up_max);<br />
        $up_max_size = &#8220;Megabytes&#8221;;<br />
        $post_max = ini_get(&#8220;post_max_size&#8221;);<br />
        $post_max = str_replace(&#8220;M&#8221;,&#8221;",$post_max);<br />
        $post_max_size = &#8220;Megabytes&#8221;;<br />
        $input_max = ini_get(&#8220;max_input_time&#8221;);<br />
        $mem_limit = ini_get(&#8220;memory_limit&#8221;);<br />
        $mem_limit = str_replace(&#8220;M&#8221;,&#8221;",$mem_limit);<br />
        $mem_limit_size = &#8220;Megabytes&#8221;;<br />
        $exec_time = ini_get(&#8220;max_execution_time&#8221;);<br />
        $safe_mode = ini_get(&#8220;safe_mode&#8221;);</p>
<p>        if(!is_null($d_func) &#038;&#038; $d_func !== &#8220;&#8221;){echo  &#8220;Disabled Functions: \n $d_func&#8221;;}<br />
        if(!is_null($safe_mode) &#038;&#038; $safe_mode !== &#8220;&#8221;){echo  &#8220;&lt;span style=&#8217;color:red;&#8217;&gt;Safe Mode is Active&lt;/span&gt; &lt;br&gt;&#8221;;}<br />
        if($up_max >= 1001){$up_max = $up_max / 1024; $up_max_size = &#8220;Gigabytes&#8221;;<br />
        if($up_max >= 10001){$up_max = $up_max / 1024; $up_max_size = &#8220;Terabytes&#8221;;}}<br />
        if($post_max >= 1001){$post_max = $post_max / 1024; $post_max_size = &#8220;Gigabytes&#8221;;<br />
        if($post_max >= 10001){$post_max = $post_max / 1024;$post_max_size = &#8220;Terabytes&#8221;;}}<br />
        if (min($input_max,60)){$input_max = $input_max /60;}<br />
        if (min($exec_time,60)){$exec_time = $exec_time /60;}<br />
        if($mem_limit >= 1001){$mem_limit = $mem_limit / 1024; $mem_limit_size = &#8220;Gigabytes&#8221;;}</p>
<p>        echo &#8220;Maximum Upload Size = $up_max $up_max_size&lt;br&gt;&#8221;;<br />
        echo &#8220;Maximum Post Size = $post_max $post_max_size &lt;br&gt;&#8221;;<br />
        echo &#8220;Maximum Input Time = $input_max minute/s&lt;br&gt;&#8221;;<br />
        echo &#8220;Memory Limit = $mem_limit $mem_limit_size&lt;br&gt;&#8221;;<br />
        echo &#8220;Maximum Execution Time = $exec_time minute/s&lt;br&gt;&#8221;;<br />
?&gt;</p></div>
]]></content:encoded>
			<wfw:commentRss>http://boolean.co.nz/blog/php-host-settings-without-phpinfo/652/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Modulo Operator For Alternating Rows</title>
		<link>http://boolean.co.nz/blog/modulo-alternating-rows/647/</link>
		<comments>http://boolean.co.nz/blog/modulo-alternating-rows/647/#comments</comments>
		<pubDate>Fri, 30 Sep 2011 22:24:50 +0000</pubDate>
		<dc:creator>Boolean</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://boolean.co.nz/blog/?p=647</guid>
		<description><![CDATA[Alternating row colours within a grid of data can make for a more pleasant viewing experience and has become a popular styling method in recent times. I was a little incredulous at some code I saw recently to determine alternating rows so without further introduction, meet the Modulo operator which is a quick and easy [...]]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td>
<img src="http://boolean.co.nz/blog/wp-content/uploads/2009/03/php-logo.png" alt="" title="php-logo" width="203" height="107" class="aligncenter size-full wp-image-61" /></td>
</tr>
</table>
<p>Alternating row colours within a grid of data can make for a more pleasant viewing experience and has become a popular styling method in recent times. I was a little incredulous at some code I saw recently to determine alternating rows so without further introduction, meet the Modulo operator which is a quick and easy way to get up and running:</p>
<div class="codesnip-container" >for($i=0;$i<10;$i++){<br />
  if($i % 2){<br />
   // This is an even row<br />
  }else{<br />
   // This is an odd row<br />
  }<br />
}</div>
<p>I&#8217;m sure you will be able to apply this to your own css or styling within your loops.</p>
]]></content:encoded>
			<wfw:commentRss>http://boolean.co.nz/blog/modulo-alternating-rows/647/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use cURL to obtain remote filesize</title>
		<link>http://boolean.co.nz/blog/curl-remote-filesize/638/</link>
		<comments>http://boolean.co.nz/blog/curl-remote-filesize/638/#comments</comments>
		<pubDate>Mon, 19 Sep 2011 11:00:46 +0000</pubDate>
		<dc:creator>Boolean</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://boolean.co.nz/blog/?p=638</guid>
		<description><![CDATA[Sometimes you might want to determine a remote file size prior to determining further action to take. This is a quick function that utilises cURL to retrieve the file size in bytes. &#60;?php function remoteFilesize ($URL){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $URL); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $info = curl_exec($ch); curl_close($ch); [...]]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td><img src="http://boolean.co.nz/blog/wp-content/uploads/2009/03/php-logo.png" alt="" title="php-logo" width="203" height="107" class="aligncenter size-full wp-image-61" /></td>
</tr>
</table>
<p>Sometimes you might want to determine a remote file size prior to determining further action to take. This is a quick function that utilises cURL to retrieve the file size in bytes.</p>
<div class="codesnip-container" >&lt;?php<br />
function remoteFilesize ($URL){<br />
	$ch = curl_init();<br />
	curl_setopt($ch, CURLOPT_URL, $URL);<br />
	curl_setopt($ch, CURLOPT_HEADER, true);<br />
	curl_setopt($ch, CURLOPT_NOBODY, true);<br />
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);<br />
	$info = curl_exec($ch);<br />
	curl_close($ch);<br />
	$info = explode(&#8216;Content-Length:&#8217;, $info);<br />
	$info = explode(&#8220;Connection&#8221;,$info[1]);<br />
	return $info[0];<br />
}<br />
?&gt;</div>
<p>Usage is simple:</p>
<div class="codesnip-container" >echo remoteFilesize(&#8220;test.com/file.html&#8221;);</div>
]]></content:encoded>
			<wfw:commentRss>http://boolean.co.nz/blog/curl-remote-filesize/638/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get Facebook Likes and Shares via Graph API</title>
		<link>http://boolean.co.nz/blog/get-facebook-likes-and-shares-via-graph-api/626/</link>
		<comments>http://boolean.co.nz/blog/get-facebook-likes-and-shares-via-graph-api/626/#comments</comments>
		<pubDate>Sun, 11 Sep 2011 01:46:44 +0000</pubDate>
		<dc:creator>Boolean</dc:creator>
				<category><![CDATA[FaceBook]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://boolean.co.nz/blog/?p=626</guid>
		<description><![CDATA[Facebook Like and Share count can easily be obtained from the Facebook Graph API. This is an extremely quick way to look up the JSON response from Facebook so that you can further process it for your own requirements. &#60;?php $URL =&#8217;https://graph.facebook.com/cocacola&#8217;; $JSON = file_get_contents($URL); $Output = json_decode($JSON); $Likes = 0; if($Output->likes){ &#160;&#160;$Likes = $Output->likes; [...]]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td><img src="http://boolean.co.nz/blog/wp-content/uploads/2009/03/php-logo.png" alt="" title="php-logo" width="203" height="107" class="aligncenter size-full wp-image-61" />
<td></tr>
</table>
<p>Facebook Like and Share count can easily be obtained from the Facebook Graph API. This is an extremely quick way to look up the JSON response from Facebook so that you can further process it for your own requirements.</p>
<div class="codesnip-container" >&lt;?php<br />
$URL =&#8217;https://graph.facebook.com/cocacola&#8217;;<br />
$JSON = file_get_contents($URL);<br />
$Output = json_decode($JSON);<br />
$Likes = 0;<br />
if($Output->likes){<br />
&nbsp;&nbsp;$Likes = $Output->likes;<br />
}</p>
<p>echo &#8220;Number of likes for CocaCola&#8217;s Facebook Page = &#8220;.$Likes.&#8221;&lt;/br&gt;&#8221;;</p>
<p>$URL2 =&#8217;https://graph.facebook.com/http://www.coca-cola.com&#8217;;<br />
$JSON2 = file_get_contents($URL2);<br />
$Output2 = json_decode($JSON2);<br />
$Shares = 0;<br />
if($Output2->shares){<br />
&nbsp;&nbsp;$Shares = $Output2->shares;<br />
}</p>
<p>echo &#8220;Number of shares for coca-cola.com = &#8220;.$Shares;<br />
?&gt;</p></div>
<p><strong>UPDATE 29/01/2012:</strong> I&#8217;ve written a slightly different method using the PHP SDK in this post <a href="http://boolean.co.nz/blog/facebook-likes-sdk/713" title="here" target="_blank">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://boolean.co.nz/blog/get-facebook-likes-and-shares-via-graph-api/626/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Currency Conversion using Yahoo Finance API</title>
		<link>http://boolean.co.nz/blog/currency-conversion-using-yahoo-finance-api/622/</link>
		<comments>http://boolean.co.nz/blog/currency-conversion-using-yahoo-finance-api/622/#comments</comments>
		<pubDate>Sat, 10 Sep 2011 00:54:08 +0000</pubDate>
		<dc:creator>Boolean</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://boolean.co.nz/blog/?p=622</guid>
		<description><![CDATA[Just a quick and dirty PHP function to retrieve information from the Yahoo Finance API to perform a currency conversion function ConvertCurrency($From,$To,$Amount){ $URL = &#8216;http://finance.yahoo.com/d/quotes.csv?e=.csv&#038;f=sl1d1t1&#038;s=&#8217;. $From . $To .&#8217;=X&#8217;; $Handle = @fopen($URL, &#8216;r&#8217;); if ($Handle) { $Result = fgets($Handle, 4096); fclose($Handle); } $allData = explode(&#8216;,&#8217;,$Result); $Value = $allData[1]; return $Value * $Amount; } Usage: $Amount [...]]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td><img src="http://boolean.co.nz/blog/wp-content/uploads/2009/03/php-logo.png" alt="" title="php-logo" width="203" height="107" class="aligncenter size-full wp-image-61" /></td>
</tr>
</table>
<p>Just a quick and dirty PHP function to retrieve information from the Yahoo Finance API to perform a currency conversion</p>
<div class="codesnip-container" >function ConvertCurrency($From,$To,$Amount){<br />
	$URL = &#8216;http://finance.yahoo.com/d/quotes.csv?e=.csv&#038;f=sl1d1t1&#038;s=&#8217;. $From . $To .&#8217;=X&#8217;;<br />
	$Handle = @fopen($URL, &#8216;r&#8217;);</p>
<p>	if ($Handle) {<br />
    	$Result = fgets($Handle, 4096);<br />
    	fclose($Handle);<br />
	}<br />
	$allData = explode(&#8216;,&#8217;,$Result);<br />
	$Value = $allData[1];</p>
<p>	return $Value * $Amount;<br />
}</p></div>
<p>Usage:</p>
<div class="codesnip-container" >$Amount = ConvertCurrency(&#8220;NZD&#8221;,&#8221;USD&#8221;,25);</div>
]]></content:encoded>
			<wfw:commentRss>http://boolean.co.nz/blog/currency-conversion-using-yahoo-finance-api/622/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Script Execution Timer Class</title>
		<link>http://boolean.co.nz/blog/php-script-execution-timer-class/553/</link>
		<comments>http://boolean.co.nz/blog/php-script-execution-timer-class/553/#comments</comments>
		<pubDate>Wed, 23 Mar 2011 06:45:21 +0000</pubDate>
		<dc:creator>Boolean</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://boolean.co.nz/blog/?p=553</guid>
		<description><![CDATA[Often for testing the efficieny of some PHP code we use script execution calculations such as the microtime function. What is infinitely more useful however is the ability to time the execution of all, some, or multiple sections of code or series of lines. Unfortunately I cant remember the origins of this timer class &#8211; [...]]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td><img src="http://boolean.co.nz/blog/wp-content/uploads/2009/03/php-logo.png" alt="" title="php-logo" width="203" height="107" class="aligncenter size-full wp-image-61" /></td>
</tr>
</table>
<p>Often for testing the efficieny of some PHP code we use script execution calculations such as the <a href="http://php.net/manual/en/function.microtime.php">microtime</a> function. What is infinitely more useful however is the ability to time the execution of all, some, or multiple sections of code or series of lines.<br />
Unfortunately I cant remember the origins of this timer class &#8211; but this code allows you to stop, start, pause and resume timing of specific sections of your php code. Thank you, whoever you may be.</p>
<p>Download the class <a href="http://boolean.co.nz/resources/files/examples/timer.zip">here</a></p>
<p>Available methods:</p>
<p><strong>start()</strong> &#8211; start/resume the timer<br />
<strong>stop()</strong> &#8211; stop/pause the timer<br />
<strong>reset()</strong> &#8211; reset the timer<br />
<strong>get</strong>([$format]) Which can defaults to Timer::SECONDS but can also be Timer::MILLISECONDS or Timer::MICROSECONDS</p>
<p>Usage example:</p>
<div class="codesnip-container" >$timer1 = new Timer();<br />
$timer2 = new Timer();</p>
<p>$timer1->start();<br />
// do some code</p>
<p>// calculate the time it takes to run a function<br />
$timer2->start();<br />
functionX();<br />
$timer2->stop();</p>
<p>$timer1->stop();</p>
<p>print $timer1->get();<br />
print $timer2->get();</p></div>
]]></content:encoded>
			<wfw:commentRss>http://boolean.co.nz/blog/php-script-execution-timer-class/553/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>cURL in PHP to access protected sites</title>
		<link>http://boolean.co.nz/blog/curl-in-php-to-access-protected-sites/527/</link>
		<comments>http://boolean.co.nz/blog/curl-in-php-to-access-protected-sites/527/#comments</comments>
		<pubDate>Fri, 04 Mar 2011 01:13:29 +0000</pubDate>
		<dc:creator>Boolean</dc:creator>
				<category><![CDATA[FaceBook]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://boolean.co.nz/blog/?p=527</guid>
		<description><![CDATA[So I was trying to use the FaceBook PHP-SDK and ran into an issue. As the cURL was pointing to an HTTPS source I was getting this error: Failed: Error Number: 60. Reason: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed The problem was that cURL hasnt been [...]]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td>
<img src="http://boolean.co.nz/blog/wp-content/uploads/2009/03/php-logo.png" alt="" title="php-logo" width="203" height="107" class="aligncenter size-full wp-image-61" /></td>
</tr>
</table>
<p>So I was trying to use the <strong>FaceBook PHP-SDK</strong> and ran into an issue. As the cURL was pointing to an HTTPS source I was getting this error:</p>
<div class="codesnip-container" >Failed: Error Number: 60. Reason: SSL certificate problem, verify that the CA cert is OK. Details:<br />
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed</div>
<p>The problem was that cURL hasnt been configured to trust the servers HTTPS certificate, as by default cURL is not setup to trust any of the Certificate Authorities (CAs)<br />
Browsers dont have this issue as the browser developers were kind enough to include a list of default CAs, however this doesnt help us out at all&#8230;</p>
<p>A quick fix is to simply configure cURL to accept any server certificate. Obviously from a security point of view this isnt great, but if you are not passing sensitive information back and forth you should be ok.</p>
<p>Before calling curl_exec() add the following code:</p>
<div class="codesnip-container" >curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);</div>
<p>This causes cURL to blindly accept an server certificate without doing any verification with the CA that issued it.</p>
<p><strong>The Proper Fix</strong><br />
The proper fix is slightly more involved so I plan to cover it at a later stage. If you cant wait that long research the curlopt_cainfo parameter, and obtaining (and saving) a CA certificate to enable cURL to trust it.</p>
]]></content:encoded>
			<wfw:commentRss>http://boolean.co.nz/blog/curl-in-php-to-access-protected-sites/527/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP URL Shortening</title>
		<link>http://boolean.co.nz/blog/php-url-shortening/463/</link>
		<comments>http://boolean.co.nz/blog/php-url-shortening/463/#comments</comments>
		<pubDate>Thu, 11 Nov 2010 15:22:37 +0000</pubDate>
		<dc:creator>Boolean</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://boolean.co.nz/blog/?p=463</guid>
		<description><![CDATA[A current Twitter related project involves quite a few URLs and because Twitter limits you to only 140 characters per post shortening a link can be very rewarding. There are a multitude of URL shortening services on the internet and whilst perhaps not producing the shortest links, TinyURL.com requires no account in order to use [...]]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td><img src="http://boolean.co.nz/blog/wp-content/uploads/2009/03/php-logo.png" alt="" title="php-logo" width="203" height="107" class="aligncenter size-full wp-image-61" /></td>
</tr>
</table>
<p>A current Twitter related project involves quite a few URLs and because Twitter limits you to only 140 characters per post shortening a link can be very rewarding.</p>
<table>
<tr>
<td>
<img src="http://boolean.co.nz/blog/wp-content/uploads/2010/11/TinyURL_logo.png" alt="" title="TinyURL_logo" width="200" height="52" class="alignleft size-full wp-image-493" /></td>
<td>There are a multitude of URL shortening services on the internet and whilst perhaps not producing the shortest links, TinyURL.com requires no account in order to use it via PHP which makes for a very simple query:</td>
</tr>
</table>
<div class="codesnip-container" >function getTinyUrl($url) {<br />
    return file_get_contents(&#8220;http://tinyurl.com/api-create.php?url=&#8221;.$url);<br />
}</div>
<p><br/></p>
<table>
<tr>
<td><img src="http://boolean.co.nz/blog/wp-content/uploads/2010/11/bitly_logo1.png" alt="" title="bitly_logo" width="179" height="98" class="alignleft size-full wp-image-496" />
</td>
<td>bit.ly is another popular URL shortener, however it does require an easily obtainable API key. The code is below:</td>
</tr>
</table>
<div class="codesnip-container" >function getBitly($url) {<br />
    $query = file_get_contents(&#8220;http://api.bit.ly/v3/shorten?login=YOUR_LOGIN&#038;;apiKey=YOUR_APIKEY&#038;longUrl=&#8221;.$url.&#8221;&#038;format=xml&#8221;);<br />
    $element = new SimpleXmlElement($query);<br />
    $bitlyurl = $element->data->url;<br />
    if($bitlyurl){<br />
        return $bitlyurl;<br />
    } else {<br />
        return &#8217;0&#8242;;<br />
    }<br />
}</div>
<p>Dont forget to change YOUR_LOGIN and YOUR_APIKEY to your own values. I&#8217;m sure you dont need any help with usage, but as always comment if you have any issues.</p>
]]></content:encoded>
			<wfw:commentRss>http://boolean.co.nz/blog/php-url-shortening/463/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

