<?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>Coders Cult Web Development Blog &#187; PHP cURL</title>
	<atom:link href="http://coderscult.com/category/php/php-curl/feed/" rel="self" type="application/rss+xml" />
	<link>http://coderscult.com</link>
	<description>Website development - HTML/XHTML, CSS, Javascript/AJAX, PHP, MySQL</description>
	<lastBuildDate>Thu, 31 Dec 2009 12:58:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PHP cURL Cookies Example</title>
		<link>http://coderscult.com/php/php-curl/2008/05/20/php-curl-cookies-example/</link>
		<comments>http://coderscult.com/php/php-curl/2008/05/20/php-curl-cookies-example/#comments</comments>
		<pubDate>Tue, 20 May 2008 13:01:00 +0000</pubDate>
		<dc:creator>Mike Lopez</dc:creator>
				<category><![CDATA[PHP cURL]]></category>
		<category><![CDATA[PHP Programming]]></category>

		<guid isPermaLink="false">http://coderscult.com/?p=42</guid>
		<description><![CDATA[






Want to learn how to use PHP cURL with Cookies?  Well, it&#8217;s pretty simple so let&#8217;s go see the code but first let&#8217;s make a scenario&#8230;
Say we have a page called &#8216;cookiepage.php&#8217; in a particular website that checks for the cookie set by the homepage and will only return the proper output if the [...]]]></description>
			<content:encoded><![CDATA[<p>Want to learn how to use PHP cURL with Cookies?  Well, it&#8217;s pretty simple so let&#8217;s go see the code but first let&#8217;s make a scenario&#8230;</p>
<p>Say we have a page called &#8216;cookiepage.php&#8217; in a particular website that checks for the cookie set by the homepage and will only return the proper output if the cookie exists.  How do you do it?  Here&#8217;s how&#8230;</p>
<p><span id="more-42"></span></p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?php</span><br />
<span class="coMULTI">/* STEP 1. let&#8217;s create a cookie file */</span><br />
<span class="re0">$ckfile</span> = <a href="http://www.php.net/tempnam"><span class="kw3">tempnam</span></a> <span class="br0">&#40;</span><span class="st0">&quot;/tmp&quot;</span>, <span class="st0">&quot;CURLCOOKIE&quot;</span><span class="br0">&#41;</span>;</p>
<p><span class="coMULTI">/* STEP 2. visit the homepage to set the cookie properly */</span><br />
<span class="re0">$ch</span> = curl_init <span class="br0">&#40;</span><span class="st0">&quot;http://somedomain.com/&quot;</span><span class="br0">&#41;</span>;<br />
curl_setopt <span class="br0">&#40;</span><span class="re0">$ch</span>, CURLOPT_COOKIEJAR, <span class="re0">$ckfile</span><span class="br0">&#41;</span>; <br />
curl_setopt <span class="br0">&#40;</span><span class="re0">$ch</span>, CURLOPT_RETURNTRANSFER, <span class="kw2">true</span><span class="br0">&#41;</span>;<br />
<span class="re0">$output</span> = curl_exec <span class="br0">&#40;</span><span class="re0">$ch</span><span class="br0">&#41;</span>;</p>
<p><span class="coMULTI">/* STEP 3. visit cookiepage.php */</span><br />
<span class="re0">$ch</span> = curl_init <span class="br0">&#40;</span><span class="st0">&quot;http://somedomain.com/cookiepage.php&quot;</span><span class="br0">&#41;</span>;<br />
curl_setopt <span class="br0">&#40;</span><span class="re0">$ch</span>, CURLOPT_COOKIEFILE, <span class="re0">$ckfile</span><span class="br0">&#41;</span>; <br />
curl_setopt <span class="br0">&#40;</span><span class="re0">$ch</span>, CURLOPT_RETURNTRANSFER, <span class="kw2">true</span><span class="br0">&#41;</span>;<br />
<span class="re0">$output</span> = curl_exec <span class="br0">&#40;</span><span class="re0">$ch</span><span class="br0">&#41;</span>;</p>
<p><span class="coMULTI">/* here you can do whatever you want with $output */</span><br />
<span class="kw2">?&gt;</span></div>
<p>Just in case you weren&#8217;t able to catch what we did in the above example, here&#8217;s a short explanation.</p>
<ul>
<li>STEP 1 creates a temporary cookie file using the tempnam() function.</li>
<li>STEP 2 loads the homepage and saves the cookie in our temporary cookie file. The key here is this line:
<p><strong>curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile);</strong>
</li>
<li>STEP 3 loads cookiepage.php with the saved cookie with this line:
<p><strong>curl_setopt ($ch, CURLOPT_COOKIEFILE, $ckfile);</strong>
</li>
</ul>
<p>Sleek and simple ei?  Hope this PHP cURL Cookie example helped you out!</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share this Post through Social Bookmarking</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fcoderscult.com%2Fphp%2Fphp-curl%2F2008%2F05%2F20%2Fphp-curl-cookies-example%2F&amp;title=PHP%20cURL%20Cookies%20Example&amp;bodytext=Want%20to%20learn%20how%20to%20use%20PHP%20cURL%20with%20Cookies%3F%20%20Well%2C%20it%27s%20pretty%20simple%20so%20let%27s%20go%20see%20the%20code%20but%20first%20let%27s%20make%20a%20scenario...%0D%0A%0D%0ASay%20we%20have%20a%20page%20called%20%27cookiepage.php%27%20in%20a%20particular%20website%20that%20checks%20for%20the%20cookie%20set%20by%20the%20homepage" title="Digg"><img src="http://coderscult.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://sphinn.com/index.php?c=post&amp;m=submit&amp;link=http%3A%2F%2Fcoderscult.com%2Fphp%2Fphp-curl%2F2008%2F05%2F20%2Fphp-curl-cookies-example%2F" title="Sphinn"><img src="http://coderscult.com/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fcoderscult.com%2Fphp%2Fphp-curl%2F2008%2F05%2F20%2Fphp-curl-cookies-example%2F&amp;title=PHP%20cURL%20Cookies%20Example&amp;notes=Want%20to%20learn%20how%20to%20use%20PHP%20cURL%20with%20Cookies%3F%20%20Well%2C%20it%27s%20pretty%20simple%20so%20let%27s%20go%20see%20the%20code%20but%20first%20let%27s%20make%20a%20scenario...%0D%0A%0D%0ASay%20we%20have%20a%20page%20called%20%27cookiepage.php%27%20in%20a%20particular%20website%20that%20checks%20for%20the%20cookie%20set%20by%20the%20homepage" title="del.icio.us"><img src="http://coderscult.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fcoderscult.com%2Fphp%2Fphp-curl%2F2008%2F05%2F20%2Fphp-curl-cookies-example%2F&amp;t=PHP%20cURL%20Cookies%20Example" title="Facebook"><img src="http://coderscult.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fcoderscult.com%2Fphp%2Fphp-curl%2F2008%2F05%2F20%2Fphp-curl-cookies-example%2F&amp;title=PHP%20cURL%20Cookies%20Example" title="Mixx"><img src="http://coderscult.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fcoderscult.com%2Fphp%2Fphp-curl%2F2008%2F05%2F20%2Fphp-curl-cookies-example%2F&amp;title=PHP%20cURL%20Cookies%20Example&amp;annotation=Want%20to%20learn%20how%20to%20use%20PHP%20cURL%20with%20Cookies%3F%20%20Well%2C%20it%27s%20pretty%20simple%20so%20let%27s%20go%20see%20the%20code%20but%20first%20let%27s%20make%20a%20scenario...%0D%0A%0D%0ASay%20we%20have%20a%20page%20called%20%27cookiepage.php%27%20in%20a%20particular%20website%20that%20checks%20for%20the%20cookie%20set%20by%20the%20homepage" title="Google Bookmarks"><img src="http://coderscult.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fcoderscult.com%2Fphp%2Fphp-curl%2F2008%2F05%2F20%2Fphp-curl-cookies-example%2F&amp;title=PHP%20cURL%20Cookies%20Example" title="StumbleUpon"><img src="http://coderscult.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fcoderscult.com%2Fphp%2Fphp-curl%2F2008%2F05%2F20%2Fphp-curl-cookies-example%2F" title="Technorati"><img src="http://coderscult.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  href="" title="YahooMyWeb"><img src="http://coderscult.com/wp-content/plugins/sociable/images/" title="YahooMyWeb" alt="YahooMyWeb" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://coderscult.com/php/php-curl/2008/05/20/php-curl-cookies-example/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>How to Post Data with cURL in PHP</title>
		<link>http://coderscult.com/php/php-curl/2008/05/20/how-to-post-data-with-curl-in-php/</link>
		<comments>http://coderscult.com/php/php-curl/2008/05/20/how-to-post-data-with-curl-in-php/#comments</comments>
		<pubDate>Tue, 20 May 2008 12:10:26 +0000</pubDate>
		<dc:creator>Mike Lopez</dc:creator>
				<category><![CDATA[PHP cURL]]></category>
		<category><![CDATA[PHP Programming]]></category>

		<guid isPermaLink="false">http://coderscult.com/?p=40</guid>
		<description><![CDATA[Do you need to post data to a website using PHP?  It&#8217;s actually pretty easy to do.  Here&#8217;s the code.
&#60;?php
$urltopost = &#34;http://somewebsite.com/script.php&#34;;
$datatopost = array &#40;
&#34;firstname&#34; =&#62; &#34;Mike&#34;,
&#34;lastname&#34; =&#62; &#34;Lopez&#34;,
&#34;email&#34; =&#62; &#34;my@email.com&#34;,
&#41;;
&#60;span id=&#34;more-40&#34;&#62;&#60;/span&#62;
$ch = curl_init &#40;$urltopost&#41;;
curl_setopt &#40;$ch, CURLOPT_POST, true&#41;;
curl_setopt &#40;$ch, CURLOPT_POSTFIELDS, $datatopost&#41;;
curl_setopt &#40;$ch, CURLOPT_RETURNTRANSFER, true&#41;;
$returndata = curl_exec &#40;$ch&#41;;
?&#62;
And what happened?  Here&#8217;s my quick [...]]]></description>
			<content:encoded><![CDATA[<p>Do you need to post data to a website using PHP?  It&#8217;s actually pretty easy to do.  Here&#8217;s the code.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?php</span><br />
<span class="re0">$urltopost</span> = <span class="st0">&quot;http://somewebsite.com/script.php&quot;</span>;<br />
<span class="re0">$datatopost</span> = <a href="http://www.php.net/array"><span class="kw3">array</span></a> <span class="br0">&#40;</span><br />
<span class="st0">&quot;firstname&quot;</span> =&gt; <span class="st0">&quot;Mike&quot;</span>,<br />
<span class="st0">&quot;lastname&quot;</span> =&gt; <span class="st0">&quot;Lopez&quot;</span>,<br />
<span class="st0">&quot;email&quot;</span> =&gt; <span class="st0">&quot;my@email.com&quot;</span>,<br />
<span class="br0">&#41;</span>;</p>
<p>&lt;span id=<span class="st0">&quot;more-40&quot;</span>&gt;&lt;/span&gt;</p>
<p><span class="re0">$ch</span> = curl_init <span class="br0">&#40;</span><span class="re0">$urltopost</span><span class="br0">&#41;</span>;<br />
curl_setopt <span class="br0">&#40;</span><span class="re0">$ch</span>, CURLOPT_POST, <span class="kw2">true</span><span class="br0">&#41;</span>;<br />
curl_setopt <span class="br0">&#40;</span><span class="re0">$ch</span>, CURLOPT_POSTFIELDS, <span class="re0">$datatopost</span><span class="br0">&#41;</span>;<br />
curl_setopt <span class="br0">&#40;</span><span class="re0">$ch</span>, CURLOPT_RETURNTRANSFER, <span class="kw2">true</span><span class="br0">&#41;</span>;<br />
<span class="re0">$returndata</span> = curl_exec <span class="br0">&#40;</span><span class="re0">$ch</span><span class="br0">&#41;</span>;<br />
<span class="kw2">?&gt;</span></div>
<p>And what happened?  Here&#8217;s my quick explanation.</p>
<p><strong>$urltopost</strong></p>
<blockquote><p>The url where you want to post your data to</p></blockquote>
<p><strong>$datatopost</strong></p>
<blockquote><p>The post data as an associative array.  The keys are the post variables</p></blockquote>
<p><strong>$ch = curl_init ($urltopost);</strong></p>
<blockquote><p>Initializes cURL</p></blockquote>
<p><strong>curl_setopt ($ch, CURLOPT_POST, true);</strong></p>
<blockquote><p>Tells cURL that we want to send post data</p></blockquote>
<p><strong>curl_setopt ($ch, CURLOPT_POSTFIELDS, $datatopost);</strong></p>
<blockquote><p>Tells cURL what are post data is</p></blockquote>
<p><strong>curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);</strong></p>
<blockquote><p>Tells cURL to return the output of the post</p></blockquote>
<p><strong>$returndata = curl_exec ($ch);</strong></p>
<blockquote><p>Executes the cURL and saves theoutput in $returndata</p></blockquote>
<p>There ya go!  If you have questions, <a href="http://forums.coderscult.com/index.php/topic,140.new.html">just ask in our forum</a>.</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share this Post through Social Bookmarking</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fcoderscult.com%2Fphp%2Fphp-curl%2F2008%2F05%2F20%2Fhow-to-post-data-with-curl-in-php%2F&amp;title=How%20to%20Post%20Data%20with%20cURL%20in%20PHP&amp;bodytext=Do%20you%20need%20to%20post%20data%20to%20a%20website%20using%20PHP%3F%20%20It%27s%20actually%20pretty%20easy%20to%20do.%20%20Here%27s%20the%20code.%0D%0A%0D%0A%0D%0A%0D%0AAnd%20what%20happened%3F%20%20Here%27s%20my%20quick%20explanation.%0D%0A%0D%0A%24urltopost%0D%0AThe%20url%20where%20you%20want%20to%20post%20your%20data%20to%0D%0A%24datatopost%0D%0AThe%20post%20data%20as%20an%20" title="Digg"><img src="http://coderscult.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://sphinn.com/index.php?c=post&amp;m=submit&amp;link=http%3A%2F%2Fcoderscult.com%2Fphp%2Fphp-curl%2F2008%2F05%2F20%2Fhow-to-post-data-with-curl-in-php%2F" title="Sphinn"><img src="http://coderscult.com/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fcoderscult.com%2Fphp%2Fphp-curl%2F2008%2F05%2F20%2Fhow-to-post-data-with-curl-in-php%2F&amp;title=How%20to%20Post%20Data%20with%20cURL%20in%20PHP&amp;notes=Do%20you%20need%20to%20post%20data%20to%20a%20website%20using%20PHP%3F%20%20It%27s%20actually%20pretty%20easy%20to%20do.%20%20Here%27s%20the%20code.%0D%0A%0D%0A%0D%0A%0D%0AAnd%20what%20happened%3F%20%20Here%27s%20my%20quick%20explanation.%0D%0A%0D%0A%24urltopost%0D%0AThe%20url%20where%20you%20want%20to%20post%20your%20data%20to%0D%0A%24datatopost%0D%0AThe%20post%20data%20as%20an%20" title="del.icio.us"><img src="http://coderscult.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fcoderscult.com%2Fphp%2Fphp-curl%2F2008%2F05%2F20%2Fhow-to-post-data-with-curl-in-php%2F&amp;t=How%20to%20Post%20Data%20with%20cURL%20in%20PHP" title="Facebook"><img src="http://coderscult.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fcoderscult.com%2Fphp%2Fphp-curl%2F2008%2F05%2F20%2Fhow-to-post-data-with-curl-in-php%2F&amp;title=How%20to%20Post%20Data%20with%20cURL%20in%20PHP" title="Mixx"><img src="http://coderscult.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fcoderscult.com%2Fphp%2Fphp-curl%2F2008%2F05%2F20%2Fhow-to-post-data-with-curl-in-php%2F&amp;title=How%20to%20Post%20Data%20with%20cURL%20in%20PHP&amp;annotation=Do%20you%20need%20to%20post%20data%20to%20a%20website%20using%20PHP%3F%20%20It%27s%20actually%20pretty%20easy%20to%20do.%20%20Here%27s%20the%20code.%0D%0A%0D%0A%0D%0A%0D%0AAnd%20what%20happened%3F%20%20Here%27s%20my%20quick%20explanation.%0D%0A%0D%0A%24urltopost%0D%0AThe%20url%20where%20you%20want%20to%20post%20your%20data%20to%0D%0A%24datatopost%0D%0AThe%20post%20data%20as%20an%20" title="Google Bookmarks"><img src="http://coderscult.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fcoderscult.com%2Fphp%2Fphp-curl%2F2008%2F05%2F20%2Fhow-to-post-data-with-curl-in-php%2F&amp;title=How%20to%20Post%20Data%20with%20cURL%20in%20PHP" title="StumbleUpon"><img src="http://coderscult.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fcoderscult.com%2Fphp%2Fphp-curl%2F2008%2F05%2F20%2Fhow-to-post-data-with-curl-in-php%2F" title="Technorati"><img src="http://coderscult.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  href="" title="YahooMyWeb"><img src="http://coderscult.com/wp-content/plugins/sociable/images/" title="YahooMyWeb" alt="YahooMyWeb" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://coderscult.com/php/php-curl/2008/05/20/how-to-post-data-with-curl-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP cURL Tutorial and Example</title>
		<link>http://coderscult.com/php/php-curl/2008/05/20/php-curl-tutorial-and-example/</link>
		<comments>http://coderscult.com/php/php-curl/2008/05/20/php-curl-tutorial-and-example/#comments</comments>
		<pubDate>Tue, 20 May 2008 12:04:00 +0000</pubDate>
		<dc:creator>Mike Lopez</dc:creator>
				<category><![CDATA[PHP cURL]]></category>
		<category><![CDATA[PHP Programming]]></category>

		<guid isPermaLink="false">http://coderscult.com/?p=41</guid>
		<description><![CDATA[Do you want to learn how to use cURL in PHP?  Well, if so then this tutorial is for you.  But before anything else, what is cURL?
cURL is a command line tool for transferring files with URL syntax. The strong point of cURL is the number of data transfer protocols it supports. It [...]]]></description>
			<content:encoded><![CDATA[<p>Do you want to learn how to use cURL in PHP?  Well, if so then this tutorial is for you.  But before anything else, what is cURL?</p>
<blockquote><p>cURL is a command line tool for transferring files with URL syntax. The strong point of cURL is the number of data transfer protocols it supports. It is distributed under the MIT License which makes cURL free software.  It supports FTP, FTPS, HTTP, HTTPS, TFTP, SCP, SFTP, Telnet, DICT, FILE and LDAP. &#8211; <a href="http://en.wikipedia.org/wiki/CURL" target="_blank">based on Wikipedia&#8217;s definition</a></p></blockquote>
<p><span id="more-41"></span></p>
<p>PHP cURL allows you to read websites, make automated logins, upload files and many more.  I&#8217;m personally using it to automate updating of my many websites.</p>
<p>Now that you know what cURL is, I think it&#8217;s time to look at some code.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?php</span><br />
<span class="re0">$ch</span> = curl_init <span class="br0">&#40;</span><span class="st0">&quot;http://www.yahoo.com&quot;</span><span class="br0">&#41;</span>;<br />
curl_setopt <span class="br0">&#40;</span><span class="re0">$ch</span>, CURLOPT_RETURNTRANSFER, <span class="kw2">true</span><span class="br0">&#41;</span>;<br />
<span class="re0">$yahoo</span> = curl_exec <span class="br0">&#40;</span><span class="re0">$ch</span><span class="br0">&#41;</span>;<br />
<span class="kw2">?&gt;</span></div>
<p>The simple example above simply gets the contents of <strong>www.yahoo.com</strong> and saves it in the variable <strong>$yahoo</strong>.  Here&#8217;s a line-by-line explanation:</p>
<p><strong>$ch = curl_init (&quot;http://www.yahoo.com&quot;);</strong></p>
<blockquote><p>Initialize curl with the URL of yahoo</p></blockquote>
<p><strong>curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);</strong></p>
<blockquote><p>Tell php curl that we want the data returned to us instead of being displayed</p></blockquote>
<p><strong>$yahoo = curl_exec ($ch);</strong></p>
<blockquote><p>Execute curl and put the output in $yahoo.</p></blockquote>
<p>But, that&#8217;s too simple!  That can be done in simpler ways with PHP&#8217;s file functions such as file() and file_get_contents()!  True but that&#8217;s where the comparison ends.</p>
<p>The power of PHP cURL lies within the curl_setopt() function.  This function instructs cURL of what exactly we want to do.  Let&#8217;s say, what if a webpage that you want to access checks for the HTTP_REFERER header?  Or perhaps, what if you need to access a webpage that works correctly only if cookies are enabled?</p>
<p>Here&#8217;s another example&#8230; This time we specify the HTTP_REFERER&#8230;</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?php</span><br />
<span class="re0">$ch</span> = curl_init <span class="br0">&#40;</span><span class="st0">&quot;http://www.somedomain.com/page2.php&quot;</span><span class="br0">&#41;</span>;<br />
curl_setopt <span class="br0">&#40;</span><span class="re0">$ch</span>, CURLOPT_RETURNTRANSFER, <span class="kw2">true</span><span class="br0">&#41;</span>;<br />
curl_setopt <span class="br0">&#40;</span><span class="re0">$ch</span>, CURLOPT_REFERER, <span class="st0">&quot;http://www.somedomain.com/page1.php&quot;</span><span class="br0">&#41;</span>;<br />
<span class="re0">$page</span> = curl_exec <span class="br0">&#40;</span><span class="re0">$ch</span><span class="br0">&#41;</span>;<br />
<span class="kw2">?&gt;</span></div>
<p>In this example, the CURLOPT_REFERER line tells cURL to set the HTTP_REFERER header to http://www.somedomain.com/page1.php.</p>
<p>PHP cURL can do more.  It can send POST data, it can log on to a website and automate tasks as if it was a real person and much more.  That&#8217;s it for now and I hope this PHP cURL Tutorial helped you.</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share this Post through Social Bookmarking</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fcoderscult.com%2Fphp%2Fphp-curl%2F2008%2F05%2F20%2Fphp-curl-tutorial-and-example%2F&amp;title=PHP%20cURL%20Tutorial%20and%20Example&amp;bodytext=Do%20you%20want%20to%20learn%20how%20to%20use%20cURL%20in%20PHP%3F%20%20Well%2C%20if%20so%20then%20this%20tutorial%20is%20for%20you.%20%20But%20before%20anything%20else%2C%20what%20is%20cURL%3F%0D%0A%0D%0AcURL%20is%20a%20command%20line%20tool%20for%20transferring%20files%20with%20URL%20syntax.%20The%20strong%20point%20of%20cURL%20is%20the%20number%20of%20data%20tr" title="Digg"><img src="http://coderscult.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://sphinn.com/index.php?c=post&amp;m=submit&amp;link=http%3A%2F%2Fcoderscult.com%2Fphp%2Fphp-curl%2F2008%2F05%2F20%2Fphp-curl-tutorial-and-example%2F" title="Sphinn"><img src="http://coderscult.com/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fcoderscult.com%2Fphp%2Fphp-curl%2F2008%2F05%2F20%2Fphp-curl-tutorial-and-example%2F&amp;title=PHP%20cURL%20Tutorial%20and%20Example&amp;notes=Do%20you%20want%20to%20learn%20how%20to%20use%20cURL%20in%20PHP%3F%20%20Well%2C%20if%20so%20then%20this%20tutorial%20is%20for%20you.%20%20But%20before%20anything%20else%2C%20what%20is%20cURL%3F%0D%0A%0D%0AcURL%20is%20a%20command%20line%20tool%20for%20transferring%20files%20with%20URL%20syntax.%20The%20strong%20point%20of%20cURL%20is%20the%20number%20of%20data%20tr" title="del.icio.us"><img src="http://coderscult.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fcoderscult.com%2Fphp%2Fphp-curl%2F2008%2F05%2F20%2Fphp-curl-tutorial-and-example%2F&amp;t=PHP%20cURL%20Tutorial%20and%20Example" title="Facebook"><img src="http://coderscult.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fcoderscult.com%2Fphp%2Fphp-curl%2F2008%2F05%2F20%2Fphp-curl-tutorial-and-example%2F&amp;title=PHP%20cURL%20Tutorial%20and%20Example" title="Mixx"><img src="http://coderscult.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fcoderscult.com%2Fphp%2Fphp-curl%2F2008%2F05%2F20%2Fphp-curl-tutorial-and-example%2F&amp;title=PHP%20cURL%20Tutorial%20and%20Example&amp;annotation=Do%20you%20want%20to%20learn%20how%20to%20use%20cURL%20in%20PHP%3F%20%20Well%2C%20if%20so%20then%20this%20tutorial%20is%20for%20you.%20%20But%20before%20anything%20else%2C%20what%20is%20cURL%3F%0D%0A%0D%0AcURL%20is%20a%20command%20line%20tool%20for%20transferring%20files%20with%20URL%20syntax.%20The%20strong%20point%20of%20cURL%20is%20the%20number%20of%20data%20tr" title="Google Bookmarks"><img src="http://coderscult.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fcoderscult.com%2Fphp%2Fphp-curl%2F2008%2F05%2F20%2Fphp-curl-tutorial-and-example%2F&amp;title=PHP%20cURL%20Tutorial%20and%20Example" title="StumbleUpon"><img src="http://coderscult.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fcoderscult.com%2Fphp%2Fphp-curl%2F2008%2F05%2F20%2Fphp-curl-tutorial-and-example%2F" title="Technorati"><img src="http://coderscult.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  href="" title="YahooMyWeb"><img src="http://coderscult.com/wp-content/plugins/sociable/images/" title="YahooMyWeb" alt="YahooMyWeb" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://coderscult.com/php/php-curl/2008/05/20/php-curl-tutorial-and-example/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
