<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: HTTP Class for PHP (supports both cURL and fsockopen)</title>
	<atom:link href="http://phpfour.com/blog/2008/01/php-http-class/feed/" rel="self" type="application/rss+xml" />
	<link>http://phpfour.com/blog/2008/01/php-http-class/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=php-http-class</link>
	<description>The everyday sharing of Emran Hasan on software development.</description>
	<lastBuildDate>Mon, 02 Apr 2012 13:35:25 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Jannik</title>
		<link>http://phpfour.com/blog/2008/01/php-http-class/#comment-23534</link>
		<dc:creator>Jannik</dc:creator>
		<pubDate>Sat, 08 Oct 2011 16:59:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpfour.com/blog/2008/01/20/php-http-class/#comment-23534</guid>
		<description>include_once(&#039;class.http.php&#039;);
$http = new Http();
$http-&gt;setMethod(&#039;POST&#039;);
$http-&gt;addParam(&#039;email&#039; , &#039;sry);
$http-&gt;addParam(&#039;pass&#039;  , &#039;bla&#039;);
$http-&gt;setReferrer(&#039;http://facebook.com/&#039;);
$http-&gt;execute(&#039;https://login.facebook.com/login.php&#039;);
echo ($http-&gt;error) ? $http-&gt;error : $http-&gt;result;

sorry, code wasnt submitted correctly, here you ...</description>
		<content:encoded><![CDATA[<p>include_once(&#8216;class.http.php&#8217;);<br />
$http = new Http();<br />
$http-&gt;setMethod(&#8216;POST&#8217;);<br />
$http-&gt;addParam(&#8216;email&#8217; , &#8216;sry);<br />
$http-&gt;addParam(&#8216;pass&#8217;  , &#8216;bla&#8217;);<br />
$http-&gt;setReferrer(&#8216;<a href="http://facebook.com/" rel="nofollow">http://facebook.com/</a>&#8216;);<br />
$http-&gt;execute(&#8216;<a href="https://login.facebook.com/login.php" rel="nofollow">https://login.facebook.com/login.php</a>&#8216;);<br />
echo ($http-&gt;error) ? $http-&gt;error : $http-&gt;result;</p>
<p>sorry, code wasnt submitted correctly, here you &#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jannik</title>
		<link>http://phpfour.com/blog/2008/01/php-http-class/#comment-23533</link>
		<dc:creator>Jannik</dc:creator>
		<pubDate>Sat, 08 Oct 2011 16:58:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpfour.com/blog/2008/01/20/php-http-class/#comment-23533</guid>
		<description>Hello,

this Class is excellent:

Could you tell me, why Facebook keeps saying: Cookies not enabled?

I&#039;ve been using it like this:

setMethod(&#039;POST&#039;);
$http-&gt;addParam(&#039;email&#039; , &#039;myemail&#039;);
$http-&gt;addParam(&#039;pass&#039;  , &#039;mypassword&#039;);
$http-&gt;setReferrer(&#039;http://facebook.com/&#039;);
$http-&gt;execute(&#039;https://login.facebook.com/login.php&#039;);
echo ($http-&gt;error) ? $http-&gt;error : $http-&gt;result;
?&gt;

Any solution would be very nice!</description>
		<content:encoded><![CDATA[<p>Hello,</p>
<p>this Class is excellent:</p>
<p>Could you tell me, why Facebook keeps saying: Cookies not enabled?</p>
<p>I&#8217;ve been using it like this:</p>
<p>setMethod(&#8216;POST&#8217;);<br />
$http-&gt;addParam(&#8216;email&#8217; , &#8216;myemail&#8217;);<br />
$http-&gt;addParam(&#8216;pass&#8217;  , &#8216;mypassword&#8217;);<br />
$http-&gt;setReferrer(&#8216;<a href="http://facebook.com/" rel="nofollow">http://facebook.com/</a>&#8216;);<br />
$http-&gt;execute(&#8216;<a href="https://login.facebook.com/login.php" rel="nofollow">https://login.facebook.com/login.php</a>&#8216;);<br />
echo ($http-&gt;error) ? $http-&gt;error : $http-&gt;result;<br />
?&gt;</p>
<p>Any solution would be very nice!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Plsnhat</title>
		<link>http://phpfour.com/blog/2008/01/php-http-class/#comment-18275</link>
		<dc:creator>Plsnhat</dc:creator>
		<pubDate>Tue, 30 Aug 2011 10:04:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpfour.com/blog/2008/01/20/php-http-class/#comment-18275</guid>
		<description>To make custom headers possible, add the method:


	
	/**
	 * Add a header to the request
	 * 
	 * @param string Name of header
	 * @param string Value of header
	 * @return void
	 */
	function addHeader($name, $value){
		if(!empty($name) &amp;&amp; !empty($value)){
			$this-&gt;headers[] = $name . &quot;: &quot; . $value;
		}
	}

In method execute() add 
        
            curl_setopt($ch, CURLOPT_HTTPHEADER,	$this-&gt;headers);		// Set custom headers	

after

            curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);                 // Return in string

and 

			// Set custom headers
			foreach($this-&gt;headers as $header){
				$requestHeader .= $header;
			}

after

            $requestHeader .= &quot;Content-Type: application/x-www-form-urlencoded\r\n&quot;;

Be aware: It will not be checked whether you will overwrite default headers! So be cautious!</description>
		<content:encoded><![CDATA[<p>To make custom headers possible, add the method:</p>
<p>	/**<br />
	 * Add a header to the request<br />
	 *<br />
	 * @param string Name of header<br />
	 * @param string Value of header<br />
	 * @return void<br />
	 */<br />
	function addHeader($name, $value){<br />
		if(!empty($name) &amp;&amp; !empty($value)){<br />
			$this-&gt;headers[] = $name . &#8220;: &#8221; . $value;<br />
		}<br />
	}</p>
<p>In method execute() add </p>
<p>            curl_setopt($ch, CURLOPT_HTTPHEADER,	$this-&gt;headers);		// Set custom headers	</p>
<p>after</p>
<p>            curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);                 // Return in string</p>
<p>and </p>
<p>			// Set custom headers<br />
			foreach($this-&gt;headers as $header){<br />
				$requestHeader .= $header;<br />
			}</p>
<p>after</p>
<p>            $requestHeader .= &#8220;Content-Type: application/x-www-form-urlencoded\r\n&#8221;;</p>
<p>Be aware: It will not be checked whether you will overwrite default headers! So be cautious!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Plsnhat</title>
		<link>http://phpfour.com/blog/2008/01/php-http-class/#comment-18273</link>
		<dc:creator>Plsnhat</dc:creator>
		<pubDate>Tue, 30 Aug 2011 09:44:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpfour.com/blog/2008/01/20/php-http-class/#comment-18273</guid>
		<description>To prevent E_DEPRECATED notice, you should replace:

!eregi($match = &quot;^http/[0-9]+\\.[0-9]+[ \t]+([0-9]+)[ \t]*(.*)\$&quot;, $headers[0], $matches)

with:

if(!preg_match(&quot;/^http\/[0-9]+\.[0-9]+[ \t]+([0-9]+)[ \t]*(.*)$/i&quot;, $headers[0], $matches))</description>
		<content:encoded><![CDATA[<p>To prevent E_DEPRECATED notice, you should replace:</p>
<p>!eregi($match = &#8220;^http/[0-9]+\\.[0-9]+[ \t]+([0-9]+)[ \t]*(.*)\$&#8221;, $headers[0], $matches)</p>
<p>with:</p>
<p>if(!preg_match(&#8220;/^http\/[0-9]+\.[0-9]+[ \t]+([0-9]+)[ \t]*(.*)$/i&#8221;, $headers[0], $matches))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Plsnhat</title>
		<link>http://phpfour.com/blog/2008/01/php-http-class/#comment-18271</link>
		<dc:creator>Plsnhat</dc:creator>
		<pubDate>Tue, 30 Aug 2011 09:33:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpfour.com/blog/2008/01/20/php-http-class/#comment-18271</guid>
		<description>There&#039;s an error: When trying to do a request with an url not available, the following code will return false for $content:

            // Get the target contents
            $content = curl_exec($ch);

As the result, the following code is not valid (because $contentArray is not existing):

            $this-&gt;_parseHeaders($contentArray[count($contentArray) - 2]);

You can fix this bug by using the following code at the end of execute():

            // Get the target contents
            $content = curl_exec($ch);
                        
            // Store the error (is any)
            $this-&gt;_setError(curl_error($ch));
			
			// Check if could not load content
			if($content===false){
				throw new httpCurlExecFailed($this-&gt;error);
			}
            $contentArray = explode(&quot;\r\n\r\n&quot;, $content);
            
            // Get the request info 
            $status  = curl_getinfo($ch);
            
            // Store the contents
            $this-&gt;result = $contentArray[count($contentArray) - 1]; 

            // Parse the headers
            $this-&gt;_parseHeaders($contentArray[count($contentArray) - 2]);
            
            // Close PHP cURL handle
            curl_close($ch);

You only need the following class:



You may now fetch this exception:

			try {
				$req-&gt;execute($url);
			} catch(httpCurlExecFailed $e){
				echo &quot;Error while executing request: &quot; . $e-&gt;getMessage . &quot;\r\n&quot;;
			}</description>
		<content:encoded><![CDATA[<p>There&#8217;s an error: When trying to do a request with an url not available, the following code will return false for $content:</p>
<p>            // Get the target contents<br />
            $content = curl_exec($ch);</p>
<p>As the result, the following code is not valid (because $contentArray is not existing):</p>
<p>            $this-&gt;_parseHeaders($contentArray[count($contentArray) - 2]);</p>
<p>You can fix this bug by using the following code at the end of execute():</p>
<p>            // Get the target contents<br />
            $content = curl_exec($ch);</p>
<p>            // Store the error (is any)<br />
            $this-&gt;_setError(curl_error($ch));</p>
<p>			// Check if could not load content<br />
			if($content===false){<br />
				throw new httpCurlExecFailed($this-&gt;error);<br />
			}<br />
            $contentArray = explode(&#8220;\r\n\r\n&#8221;, $content);</p>
<p>            // Get the request info<br />
            $status  = curl_getinfo($ch);</p>
<p>            // Store the contents<br />
            $this-&gt;result = $contentArray[count($contentArray) - 1]; </p>
<p>            // Parse the headers<br />
            $this-&gt;_parseHeaders($contentArray[count($contentArray) - 2]);</p>
<p>            // Close PHP cURL handle<br />
            curl_close($ch);</p>
<p>You only need the following class:</p>
<p>You may now fetch this exception:</p>
<p>			try {<br />
				$req-&gt;execute($url);<br />
			} catch(httpCurlExecFailed $e){<br />
				echo &#8220;Error while executing request: &#8221; . $e-&gt;getMessage . &#8220;\r\n&#8221;;<br />
			}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: motobineuse</title>
		<link>http://phpfour.com/blog/2008/01/php-http-class/#comment-206</link>
		<dc:creator>motobineuse</dc:creator>
		<pubDate>Wed, 07 Jul 2010 17:10:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpfour.com/blog/2008/01/20/php-http-class/#comment-206</guid>
		<description>i love this bog, i just bookmarked it to my delicious, thank you for posting this.</description>
		<content:encoded><![CDATA[<p>i love this bog, i just bookmarked it to my delicious, thank you for posting this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Code Updates (HTTP class, Extended CodeIgniter Model, Cross-domain AJAX transport) &#124; PHP Tutorials</title>
		<link>http://phpfour.com/blog/2008/01/php-http-class/#comment-205</link>
		<dc:creator>Code Updates (HTTP class, Extended CodeIgniter Model, Cross-domain AJAX transport) &#124; PHP Tutorials</dc:creator>
		<pubDate>Sun, 16 May 2010 16:06:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpfour.com/blog/2008/01/20/php-http-class/#comment-205</guid>
		<description>[...] original post is here for [...]</description>
		<content:encoded><![CDATA[<p>[...] original post is here for [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Emran Hasan</title>
		<link>http://phpfour.com/blog/2008/01/php-http-class/#comment-204</link>
		<dc:creator>Emran Hasan</dc:creator>
		<pubDate>Fri, 23 Apr 2010 13:29:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpfour.com/blog/2008/01/20/php-http-class/#comment-204</guid>
		<description>@MiniGod - The class has not been updated for a long time and does have a few more issues. I&#039;d suggest you use the PECL HTTP extension - it&#039;s a good one and these days I use that too.</description>
		<content:encoded><![CDATA[<p>@MiniGod &#8211; The class has not been updated for a long time and does have a few more issues. I&#8217;d suggest you use the PECL HTTP extension &#8211; it&#8217;s a good one and these days I use that too.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MiniGod</title>
		<link>http://phpfour.com/blog/2008/01/php-http-class/#comment-203</link>
		<dc:creator>MiniGod</dc:creator>
		<pubDate>Fri, 23 Apr 2010 10:25:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpfour.com/blog/2008/01/20/php-http-class/#comment-203</guid>
		<description>Oh. And i also get a few warnings. Mostly &quot;Undefined variable: cookieString&quot;, also &quot;Undefined index: transfer-encoding&quot; etc....</description>
		<content:encoded><![CDATA[<p>Oh. And i also get a few warnings. Mostly &#8220;Undefined variable: cookieString&#8221;, also &#8220;Undefined index: transfer-encoding&#8221; etc&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MiniGod</title>
		<link>http://phpfour.com/blog/2008/01/php-http-class/#comment-202</link>
		<dc:creator>MiniGod</dc:creator>
		<pubDate>Fri, 23 Apr 2010 10:21:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpfour.com/blog/2008/01/20/php-http-class/#comment-202</guid>
		<description>Hey. I&#039;ve been trying out your class, but i get an error on most websites:
&quot;501 Not Implemented&quot; or &quot;404 Bad Request&quot; with the body &quot;Method Not Implemented&quot;.
I get that last error in your own test_fbapp.php script.

I do not know why i get this. Do you?
Same error in both PHP 5.3.0 and PHP 5.2.11.</description>
		<content:encoded><![CDATA[<p>Hey. I&#8217;ve been trying out your class, but i get an error on most websites:<br />
&#8220;501 Not Implemented&#8221; or &#8220;404 Bad Request&#8221; with the body &#8220;Method Not Implemented&#8221;.<br />
I get that last error in your own test_fbapp.php script.</p>
<p>I do not know why i get this. Do you?<br />
Same error in both PHP 5.3.0 and PHP 5.2.11.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced

Served from: phpfour.com @ 2012-05-17 18:59:43 -->
