<?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>Webmaster-Source &#187; HTTP</title>
	<atom:link href="https://www.webmaster-source.com/tag/http/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.webmaster-source.com</link>
	<description>Useful Resources For Webmasters</description>
	<lastBuildDate>Thu, 24 Aug 2017 02:01:18 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.42</generator>
	<item>
		<title>WordPress HTTP Request Class</title>
		<link>https://www.webmaster-source.com/2010/03/29/wordpress-http-request-class/</link>
		<comments>https://www.webmaster-source.com/2010/03/29/wordpress-http-request-class/#comments</comments>
		<pubDate>Mon, 29 Mar 2010 11:33:39 +0000</pubDate>
		<dc:creator><![CDATA[Matt]]></dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.webmaster-source.com/?p=3120</guid>
		<description><![CDATA[Many WordPress plugin and theme developers eventually find the need to have their application make HTTP requests to a remote server. One example would be to make calls to the Twitter API, which involves making GET and POST requests and collecting the XML/JSON response. There are many ways to make HTTP requests with PHP, such [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Many WordPress plugin and theme developers eventually find the need to have their application make HTTP requests to a remote server. One example would be to make calls to the Twitter API, which involves making GET and POST requests and collecting the XML/JSON response.</p>
<p>There are many ways to make HTTP requests with PHP, such as cURL or fopen(), but the problem is that not everyone has the same server configuration. Some users may not have cURL installed, others may have fopen() or file_get_contents() disabled by their host. How do you find a solution that can accommodate everyone? You <em>could</em> write a set of functions that check to see which HTTP request components are available and then choose one to make the request. Or you could take the easy route and use the handy class built into WordPress.</p>
<p><a href="http://www.binarymoon.co.uk/2010/03/wordpress-http-read-content-from-other-websites/">The WP_Http class</a> is an easy way to avoid the rigamarole and get back to the fun part of programming. It serves as a wrapper to separate the <em>how</em> from the equation, creating an abstract device to handle the requests.</p>
<pre class="brush: php; title: ; notranslate">
$url = 'http://search.twitter.com/search.json?q=from%3Aredwall_hp&amp;rpp=5';

$request = new WP_Http;
$result = $request-&gt;request($url);
$content = array();

if (isset($result-&gt;errors)) {
 // display error message of some sort
} else {
 $content = $result['body'];
}
</pre>
<p>After Ben Gillbanks&#8217; post pointed this class out to me, I did some searching and found <a href="http://planetozh.com/blog/2009/08/how-to-make-http-requests-with-wordpress/">Ozh&#8217;s more in-depth post</a>, which shows how to send POST requests and HTTP headers.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.webmaster-source.com/2010/03/29/wordpress-http-request-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Basic HTTP Authentication With PHP</title>
		<link>https://www.webmaster-source.com/2009/06/03/basic-http-authentication-with-php/</link>
		<comments>https://www.webmaster-source.com/2009/06/03/basic-http-authentication-with-php/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 11:25:43 +0000</pubDate>
		<dc:creator><![CDATA[Matt]]></dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.webmaster-source.com/?p=2235</guid>
		<description><![CDATA[Basic HTTP authentication is rudimentary method of requesting a username and password, then allowing or denying access based on the credentials entered. You&#8217;ve probably seen it in action somewhere or another. If you try to subscribe to a protected RSS feed, such as the feed for your friends timeline on Twitter, for example. It&#8217;s not [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Basic HTTP authentication is rudimentary method of requesting a username and password, then allowing or denying access based on the credentials entered. You&#8217;ve probably seen it in action somewhere or another. If you try to subscribe to a protected RSS feed, such as the feed for your friends timeline on Twitter, for example.</p>
<p>It&#8217;s not the most user-friendly way to authenticate a user, but it has it&#8217;s uses. It&#8217;s great for APIs and other things where a pretty interface isn&#8217;t being delivered, where a more low-level solution is required. It&#8217;s also good for restricting access to parts of your server that most people just don&#8217;t need to be accessing.</p>
<p><img style=' display: block; margin-right: auto; margin-left: auto;'  class="aligncenter size-full wp-image-2236" title="Basic HTTP Authentication" src="//www.webmaster-source.com/wp-content/uploads/httpbasicauth.jpg" alt="Basic HTTP Authentication" width="500" height="212" /></p>
<p><span id="more-2235"></span>Now how do you do that for yourself? It&#8217;s a fairly simple matter with PHP. Basically you send an <code>HTTP/1.0Â 401Â Unauthorized</code> header, and a <code>WWW-Authenticate: Basic realm="Name of Realm"</code>. This tells the client that it&#8217;s not authorized to view the page, and that it should try to become authorized.</p>
<p>That&#8217;s all it takes to have the little box show up and demand a username and password. Now all you have to do is check the submitted username and password against the correct ones. Simply check the <code>$_SERVER['PHP_AUTH_USER']</code> and <code>$_SERVER['PHP_AUTH_PW']</code> global variables.</p>
<p>Here&#8217;s an example of a minimal script to request and check a username and password:</p>
<pre class="brush: php; title: ; notranslate">&lt;?php

if ( !isset($_SERVER['PHP_AUTH_USER']) ) {
header('WWW-Authenticate: Basic realm=&quot;You Shall Not Pass&quot;');
header('HTTP/1.0 401 Unauthorized');
exit;
}
else {
if ( $_SERVER['PHP_AUTH_USER'] == 'me' &amp;&amp; $_SERVER['PHP_AUTH_PW'] == 'password' ) {
echo &quot;&lt;p&gt;Welcome, {$_SERVER['PHP_AUTH_USER']}.&lt;/p&gt;&quot;;
} else {
echo &quot;Wrong password, Balrog!&quot;;
}
}

?&gt;</pre>
<p>A quick word of caution: Whenever you store passwords, be they in a database, text file or simply hard-coded into the script, you should always encrypt them with a one-way hash. The PHP Security Consortium has <a href="http://phpsec.org/articles/2005/password-hashing.html">an article on how to do this</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.webmaster-source.com/2009/06/03/basic-http-authentication-with-php/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/


Served from: www.webmaster-source.com @ 2026-06-10 02:31:02 by W3 Total Cache
-->