<?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>TechPHP.org&#187; PHP</title>
	<atom:link href="http://www.techphp.org/category/general/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.techphp.org</link>
	<description>Web development journal</description>
	<lastBuildDate>Tue, 15 Dec 2009 00:04:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Denied access with pure PHP</title>
		<link>http://www.techphp.org/general/denied-access-with-pure-php/</link>
		<comments>http://www.techphp.org/general/denied-access-with-pure-php/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 11:05:40 +0000</pubDate>
		<dc:creator>lexa</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[access]]></category>
		<category><![CDATA[denied]]></category>
		<category><![CDATA[directory listing]]></category>
		<category><![CDATA[HTTP Header]]></category>
		<category><![CDATA[protection]]></category>

		<guid isPermaLink="false">http://www.techphp.org/?p=164</guid>
		<description><![CDATA[Often you have to protect a directory or website, so that not everybody has access to it. Besides, there are several possibilities as for example using .htaccess, but the best and quickest method as it seems to me is with PHP code.
You create a file with the name login.php, with following contents:

&#60;?php

$user = &#34;test&#34;;
$pw = [...]]]></description>
			<content:encoded><![CDATA[<p>Often you have to protect a directory or website, so that not everybody has access to it. Besides, there are several possibilities as for example using .htaccess, but the best and quickest method as it seems to me is with PHP code.</p>
<p>You create a file with the name login.php, with following contents:</p>
<pre class="brush: php;">
&lt;?php

$user = &quot;test&quot;;
$pw = &quot;12345&quot;;

function authenticate () {
  Header(&quot;WWW-authenticate: basic realm=\&quot;Restricted Area\&quot;&quot;);
  Header(&quot;HTTP/1.0 401 Unauthorized&quot;);
  echo &quot;Restricted Area!&quot;;
  exit;
}

if (!isset($_SERVER['PHP_AUTH_USER']) || $_SERVER['PHP_AUTH_USER'] != $user || $_SERVER['PHP_AUTH_PW'] != $pw) {
  authenticate();
}
?&gt;
</pre>
<p>Then you have to include the login.php to the top of index.php:</p>
<pre class="brush: php;">
&lt;?php
  include (&quot;login.php&quot;);
?&gt;
</pre>
<p>Thats all! It is important that there are no other index.* files in the directory.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techphp.org/general/denied-access-with-pure-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Browser detection in PHP</title>
		<link>http://www.techphp.org/general/browser-detection-in-php/</link>
		<comments>http://www.techphp.org/general/browser-detection-in-php/#comments</comments>
		<pubDate>Wed, 12 Nov 2008 21:32:10 +0000</pubDate>
		<dc:creator>lexa</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[difference]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[mozilla]]></category>
		<category><![CDATA[msie]]></category>
		<category><![CDATA[opera]]></category>

		<guid isPermaLink="false">http://techphp.net/?p=25</guid>
		<description><![CDATA[It was short time ago. I was sitting in my room and thinking about browser-problems in this great and sick world. Then I went to the kitchen to make a tea, but made a coffee, because I was thinking about another things. Just like the programmers of the browsers, they wanted to make a best [...]]]></description>
			<content:encoded><![CDATA[<p><img style="margin: 10px; float: right;" title="browsers" src="http://www.techphp.org/wp-content/uploads/2008/12/browsers.png" alt="browsers" width="270" height="180" />It was short time ago. I was sitting in my room and thinking about browser-problems in this great and sick world. Then I went to the kitchen to make a tea, but made a coffee, because I was thinking about another things. Just like the programmers of the browsers, they wanted to make a best browser ever, but they failed.</p>
<p>So, now about our problem. We want make our application working in all browsers, because it&#8217;s good to make it work everywhere. So we have to aks the user agent (basically the client program, not the agent Smith from Matrix), what browser are you using? And we want make it so flexible, that we can ask him this every time. For this purpose we introduce a function:</p>
<pre class="brush: php;">
function getBrowser()
{
  $ua = $_SERVER['HTTP_USER_AGENT']
  if (strstr($ua,'Opera')) {  // Opera
    $browser = ereg_replace(&quot;.+\(.+\) (Opera |v){0,1}([0-9,\.]+)[^0-9]*&quot;,&quot;Opera\\2&quot;,$ua);
    if(ereg('^Opera/.*',$ua)) {
      $browser = ereg_replace(&quot;Opera/([0-9,\.]+).*&quot;,&quot;Opera \\1&quot;,$ua);
    }
  } elseif (strstr($ua,'MSIE')) { // MSIE
    $browser=ereg_replace(&quot;.+\(.+MSIE ([0-9,\.]+).+&quot;, &quot;Internet Explorer \\1&quot;,$ua);
  } elseif (strstr($ua,'Firefox')) { // Firefox
    $browser=ereg_replace(&quot;.+\(.+rv:.+\).+Firefox/(.*)&quot;, &quot;Firefox \\1&quot;, $ua);
  } elseif (strstr($ua,'Mozilla')) {  //  Mozilla
    $browser=ereg_replace(&quot;.+\(.+rv:([0-9,\.]+).+&quot;,&quot;Mozilla \\1&quot;,$ua);
  } else {  // None of them.
    $browser=$ua;
  }
  return $browser;
}
</pre>
<p>If we want our PHP script to show us the browser, we write:</p>
<pre class="brush: php;">
echo(getBrowser());
</pre>
<p>Now we can see, what kind of browser is used and use it in our aplication:</p>
<pre class="brush: php;">
if (getBrowser() == 'Internet Explorer 6.0') {
echo (&quot;Please install another Browser&quot;);
}
</pre>
<p>Thats it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techphp.org/general/browser-detection-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
