<?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>PHP Software Developing &#187; cURL</title>
	<atom:link href="http://www.phpdeveloping.co.za/category/curl/feed" rel="self" type="application/rss+xml" />
	<link>http://www.phpdeveloping.co.za</link>
	<description>for the love of PHP Development</description>
	<lastBuildDate>Tue, 29 Sep 2009 15:38:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>HTML Headers</title>
		<link>http://www.phpdeveloping.co.za/curl/html-headers.html</link>
		<comments>http://www.phpdeveloping.co.za/curl/html-headers.html#comments</comments>
		<pubDate>Mon, 27 Jul 2009 19:48:36 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[cURL]]></category>
		<category><![CDATA[html headers]]></category>

		<guid isPermaLink="false">http://www.phpdeveloping.co.za/?p=71</guid>
		<description><![CDATA[In various circumstances I&#8217;ve needed to have PHP pull the information on HTML headers that a web server returns.  I&#8217;ve found cURL to provide an excellent solution to this.

  $htmlheader = &#34;&#34;;
&#160;
  function html_header&#40;$url&#41; &#123;
    global $htmlheader;
    $htmlheader = &#34;&#34;;
    $ch = curl_init&#40;&#41;;
 [...]]]></description>
			<content:encoded><![CDATA[<p>In various circumstances I&#8217;ve needed to have PHP pull the information on HTML headers that a web server returns.  I&#8217;ve found cURL to provide an excellent solution to this.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #000088;">$htmlheader</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">function</span> html_header<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$htmlheader</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$htmlheader</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_HEADERFUNCTION<span style="color: #339933;">,</span> <span style="color: #0000ff;">'readHeader'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_exec</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_close</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$htmlheader</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">function</span> readHeader<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> <span style="color: #000088;">$header</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$htmlheader</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$htmlheader</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$header</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">return</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$header</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>The variable will contain something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">HTTP<span style="color: #339933;">/</span><span style="color:#800080;">1.1</span> <span style="color: #cc66cc;">200</span> OK
<span style="color: #990000;">Date</span><span style="color: #339933;">:</span> Thu<span style="color: #339933;">,</span> <span style="color: #cc66cc;">23</span> Jul <span style="color: #cc66cc;">2009</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">56</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">23</span> GMT
Server<span style="color: #339933;">:</span> Apache
X<span style="color: #339933;">-</span>Powered<span style="color: #339933;">-</span>By<span style="color: #339933;">:</span> PHP<span style="color: #339933;">/</span>5<span style="color: #339933;">.</span>2<span style="color: #339933;">.</span>0<span style="color: #339933;">-</span><span style="color: #cc66cc;">8</span><span style="color: #339933;">+</span>etch13
Content<span style="color: #339933;">-</span>Type<span style="color: #339933;">:</span> text<span style="color: #339933;">/</span>html<span style="color: #339933;">;</span> charset<span style="color: #339933;">=</span>UTF<span style="color: #339933;">-</span><span style="color: #cc66cc;">8</span>
Via<span style="color: #339933;">:</span> <span style="color:#800080;">1.1</span> bc1<span style="color: #339933;">-</span>rba
Transfer<span style="color: #339933;">-</span>Encoding<span style="color: #339933;">:</span> chunked
Connection<span style="color: #339933;">:</span> Keep<span style="color: #339933;">-</span>Alive
Age<span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span></pre></div></div>

<p>There are two functions above.  html_header is just the function to does the call to the URL and collects the header information.  The header information is actually captured by the readHeader function.  </p>
<p>You need to return the length of the header back to the CURLOPT_HEADERFUNCTION call, which is where the need for the global variable comes in.  There might be a more elegant way of doing this, perhaps rather building this function into a class of it&#8217;s own.  But I hope the above shows you how to get the information you require.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpdeveloping.co.za/curl/html-headers.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Faking your User Agent with cURL</title>
		<link>http://www.phpdeveloping.co.za/curl/faking-your-user-agent-with-curl.html</link>
		<comments>http://www.phpdeveloping.co.za/curl/faking-your-user-agent-with-curl.html#comments</comments>
		<pubDate>Mon, 27 Jul 2009 15:34:18 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[cURL]]></category>
		<category><![CDATA[fake user agent]]></category>

		<guid isPermaLink="false">http://www.phpdeveloping.co.za/?p=53</guid>
		<description><![CDATA[It&#8217;s very often needed to fake your User Agent, not to do any untoward, but to test various aspects of your website.  Perhaps you want your website to display differently when using Internet Explorer 7 than when using Firefox 3.5.  For whatever reason you have, here is a simple solution I use for [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s very often needed to fake your User Agent, not to do any untoward, but to test various aspects of your website.  Perhaps you want your website to display differently when using Internet Explorer 7 than when using Firefox 3.5.  For whatever reason you have, here is a simple solution I use for my web crawlers.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$userAgent</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Firefox (WindowsXP) - Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_USERAGENT<span style="color: #339933;">,</span> <span style="color: #000088;">$userAgent</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_FAILONERROR<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_FOLLOWLOCATION<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_AUTOREFERER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_VERBOSE<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$html</span><span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>With a bit of coding you can fill up an array with all the user agent strings you can find on the Internet, and randomly use them as the user agent when using cURL.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpdeveloping.co.za/curl/faking-your-user-agent-with-curl.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
