<?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>Denie&#039;s Tech Blog &#187; PHP</title>
	<atom:link href="http://blog.nataprawira.com/tech/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.nataprawira.com/tech</link>
	<description>Information Technology for Life!</description>
	<lastBuildDate>Mon, 19 Jul 2010 09:20:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Simple Check IP with PHP</title>
		<link>http://blog.nataprawira.com/tech/2009/06/16/simple-check-ip-with-php/</link>
		<comments>http://blog.nataprawira.com/tech/2009/06/16/simple-check-ip-with-php/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 18:37:27 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Internet Protocol]]></category>
		<category><![CDATA[IP]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=56</guid>
		<description><![CDATA[

You can use below simple PHP scripting to check IP address
&#60;?php
if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){
echo &#8220;&#60;title&#62;&#8221;.$_SERVER["HTTP_X_FORWARDED_FOR"].&#8221; via &#8220;.$_SERVER["REMOTE_ADDR"].&#8221;&#60;/title&#62;\n\n&#8221;;
echo &#8220;Your IP: &#8220;.$_SERVER["HTTP_X_FORWARDED_FOR"] . &#8220;&#60;br /&#62;\n&#8221;;
echo &#8220;Proxy IP: &#8220;.$_SERVER["REMOTE_ADDR"] . &#8220;&#60;br /&#62;\n&#8221;;
$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
}else{
echo &#8220;&#60;title&#62;&#8221;.$_SERVER["REMOTE_ADDR"].&#8221;&#60;/title&#62;\n\n&#8221;;
echo &#8220;Your IP: &#8220;.$_SERVER["REMOTE_ADDR"] . &#8220;&#60;br /&#62;\n&#8221;;
$ip = $_SERVER["REMOTE_ADDR"];
}
echo &#8220;Date Time: &#8221; . date(&#8221;Y-m-d H:i:s&#8221;) . &#8220;&#60;br /&#62;\n&#8221;;
?&#62;
]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F06%2F16%2Fsimple-check-ip-with-php%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F06%2F16%2Fsimple-check-ip-with-php%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p><strong>You can use below simple PHP scripting to check IP address</strong></p>
<p>&lt;?php<br />
if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){<br />
echo &#8220;&lt;title&gt;&#8221;.$_SERVER["HTTP_X_FORWARDED_FOR"].&#8221; via &#8220;.$_SERVER["REMOTE_ADDR"].&#8221;&lt;/title&gt;\n\n&#8221;;<br />
echo &#8220;Your IP: &#8220;.$_SERVER["HTTP_X_FORWARDED_FOR"] . &#8220;&lt;br /&gt;\n&#8221;;<br />
echo &#8220;Proxy IP: &#8220;.$_SERVER["REMOTE_ADDR"] . &#8220;&lt;br /&gt;\n&#8221;;<br />
$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];<br />
}else{<br />
echo &#8220;&lt;title&gt;&#8221;.$_SERVER["REMOTE_ADDR"].&#8221;&lt;/title&gt;\n\n&#8221;;<br />
echo &#8220;Your IP: &#8220;.$_SERVER["REMOTE_ADDR"] . &#8220;&lt;br /&gt;\n&#8221;;<br />
$ip = $_SERVER["REMOTE_ADDR"];<br />
}<br />
echo &#8220;Date Time: &#8221; . date(&#8221;Y-m-d H:i:s&#8221;) . &#8220;&lt;br /&gt;\n&#8221;;<br />
?&gt;</p>
<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2009/06/16/simple-check-ip-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mixing PHP and SSI</title>
		<link>http://blog.nataprawira.com/tech/2009/03/24/mixing-php-and-ssi/</link>
		<comments>http://blog.nataprawira.com/tech/2009/03/24/mixing-php-and-ssi/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 03:54:53 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[SSI]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Mixing PHP and SSI]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=45</guid>
		<description><![CDATA[

This information is ONLY relevant to PHP4 and Apache 1.3. (BUT possible can be work also in PHP 5.x and Apache 2.x ) We historically used PHP for all our web work. We have decided to migrate to ruby for lots of reasons for all our new web development but we still have lots of [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F03%2F24%2Fmixing-php-and-ssi%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F03%2F24%2Fmixing-php-and-ssi%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p><strong>This information is ONLY relevant to PHP4 and Apache 1.3</strong>. <em><strong>(BUT possible can be work also in PHP 5.x and Apache 2.x )</strong></em> We historically used PHP for all our web work. We have decided to migrate to <a href="http://www.zytrax.com/tech/lang/ruby/" target="_blank">ruby</a> for lots of reasons for all our new web development but we still have lots of PHP stuff hanging around.</p>
<h3>Background</h3>
<p>We regularly mix PHP and SSIs for the following reasons:</p>
<ul>
<li>Laziness &#8211; we have a lot of historic SSI stuff lying around and do not want to change it. We prefer evolution to revolution.</li>
<li>Appropriateness. Not all systems are good at everything. We find that conditionally selecting &#8216;lumps&#8217; of code to deliver browser specific pages (see <a href="http://www.zytrax.com/tech/web/browser_sniffing.html" target="_blank">server side browser sniffing</a>) is a lot cleaner and easier with SSI. That does not take away from either technology.</li>
</ul>
<h3>Nesting PHP and SSI</h3>
<p>The rules go like this (PHP4 and Apache 1.3 &#8211; we understand that Apache 2 is more flexible but have not yet made the transition):</p>
<ol>
<li>You can invoke SSI files from within PHP but must use the PHP <strong>virtual()</strong> function not <strong>include()</strong>. Variables set within PHP are NOT available to SSI so our favorite &#8216;wheeze&#8217; of supplying last modified dates to a standard footer do not work.</li>
<li>You can include SSI files using the <a href="http://www.zytrax.com/tech/web/ssi.htm#include" target="_blank">include virtual</a> SSI directive but the SSI filename must have a .shtml extension even if the XBitHack is being used.</li>
<li>You cannot include PHP files using the <a href="http://www.zytrax.com/tech/web/ssi.htm#include" target="_blank">include virtual</a> SSI directive.</li>
<li>Variables set within the General Apache section (we use this <a href="http://www.zytrax.com/tech/web/browser_sniffing.html" target="_blank">technique for server side bowser sniffing</a>) are available to both .php and .shtml files no matter how they are called.</li>
</ol>
<p><strong>Note:</strong> We would guess that the Apache environment for each type of file (.php and .shtml) is initialised to the same state as when the page is first called, whereas a nested .php files uses the same php environment and therefore reflects any dynamic changes.</p>
<p><span id="more-45"></span></p>
<h2>Examples</h2>
<p>The following is our standard level 1 template implemented in SSI first and then PHP.</p>
<h3>SSI Version</h3>
<pre>&lt;!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Language" content="en-us"&gt;
&lt;meta http-equiv="Content-Type" content="text/html"&gt;
&lt;meta name="GENERATOR" content="company"&gt;
&lt;!--#include virtual="/templates/meta.html" --&gt;
&lt;title&gt;Level 1 template&lt;/title&gt;
&lt;!-- conditionally generated style sheet --&gt;
&lt;!--#include virtual="/templates/styles.shtml" --&gt;
&lt;!-- conditionally generated javascript code --&gt;
&lt;!--#include virtual="/scripts/javascript.shtml" --&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;!-- banner/page headings --&gt;
&lt;!--#include virtual="/templates/level_1.shtml" --&gt;
&lt;div class="page-content"&gt;

&lt;!-- unique page contents go here --&gt;

&lt;/div&gt;
&lt;!--#config timefmt="%B %d %Y" --&gt;
&lt;!--#set var="real_date" value="$LAST_MODIFIED" --&gt;
&lt;!--#include virtual="/templates/footer.shtml" --&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3>PHP Version</h3>
<pre>&lt;!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Language" content="en-us"&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=windows-1252"&gt;
&lt;meta name="GENERATOR" content="company"&gt;
&lt;meta name="keywords" content="blah, blah"&gt;
&lt;title&gt;Cool Tools&lt;/title&gt;
&lt;?php
&lt;!-- conditionally generated style sheet --&gt;
  virtual ("/templates/styles.shtml");
&lt;!-- conditionally generated javascript code --&gt;
  virtual ("/scripts/javascript.shtml");
?&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;?php
&lt;!-- banner/page headings --&gt;
  virtual ("/templates/level_1.shtml");
?&gt;
&lt;div class="page-content"&gt;

&lt;!-- unique page contents go here --&gt;

&lt;/div&gt;
&lt;?php
  $real_date = date("F d, Y.", getlastmod());
  include ("../templates/footer.php");
?&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p><strong>Notes:</strong></p>
<ol>
<li>You will notice that the styles, javascript and standard page navigation header use the PHP <strong>virtual()</strong> function because they contain SSI directives but the files are otherwise unchanged.</li>
<li>Our SSI &#8216;last modified&#8217; date &#8216;wheeze&#8217; for the footer does not work in a mixed PHP/SSI environment (because you cannot pass variables between PHP and SSI). Instead we have to create a &#8220;footer.php&#8221; file and set the variable &#8216;real_date&#8217; using the PHP <strong>date()</strong> and  <strong>getlastmod()</strong> functions. This file is invoked with the <strong>include()</strong> function because it is a standard PHP file. In &#8216;footer.php&#8217; we just use &#8216;echo $real_date&#8217; to place our last modified date in the output stream. Yes its simpler in PHP but now we have to maintain two versions of our standard footer.</li>
</ol>
<p><strong><a title="http://www.zytrax.com/tech/php/php_ssi.htm" href="http://www.zytrax.com/tech/php/php_ssi.htm" target="_blank">Original</a></strong></p>
<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2009/03/24/mixing-php-and-ssi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP configuration inside httpd.conf</title>
		<link>http://blog.nataprawira.com/tech/2009/03/13/php-configuration-inside-httpdconf/</link>
		<comments>http://blog.nataprawira.com/tech/2009/03/13/php-configuration-inside-httpdconf/#comments</comments>
		<pubDate>Fri, 13 Mar 2009 13:53:34 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[httpd.conf]]></category>
		<category><![CDATA[PHP Configuration]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=43</guid>
		<description><![CDATA[

How to set PHP error notice hidden in httpd.conf (vhost):

&#60;VirtualHost *:80&#62;
  ...
  php_flag display_startup_errors off
  php_flag display_errors off
  php_flag html_errors off
  ...
&#60;/VirtualHost&#62;

How to set individual php.ini in httpd.conf (vhost):

&#60;VirtualHost *:80&#62;
  ...
  PHPIniDir '/path/to/php/conf/php-foo.ini'
  ...
&#60;/VirtualHost&#62;

How to set individual PHPError.log in httpd.conf (vhost):

&#60;VirtualHost *:80&#62;
  ...
  php_flag  [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F03%2F13%2Fphp-configuration-inside-httpdconf%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F03%2F13%2Fphp-configuration-inside-httpdconf%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p><strong>How to set PHP error notice hidden in httpd.conf (vhost):</strong></p>
<blockquote>
<pre>&lt;VirtualHost *:80&gt;
  ...
  php_flag display_startup_errors off
  php_flag display_errors off
  php_flag html_errors off
  ...
&lt;/VirtualHost&gt;</pre>
</blockquote>
<p><strong>How to set individual php.ini in httpd.conf (vhost):</strong></p>
<blockquote>
<pre>&lt;VirtualHost *:80&gt;
  ...
  PHPIniDir '/path/to/php/conf/php-foo.ini'
  ...
&lt;/VirtualHost&gt;</pre>
</blockquote>
<p><strong>How to set individual PHPError.log in httpd.conf (vhost):</strong></p>
<blockquote>
<pre>&lt;VirtualHost *:80&gt;
  ...
  php_flag  log_errors on
  php_value error_log  /path/to/site/PHPerror.log
  ...
&lt;/VirtualHost&gt;</pre>
</blockquote>
<p><a title="http://perishablepress.com/press/2007/12/17/how-to-enable-php-error-logging-via-htaccess/" rel="nofollow" href="http://perishablepress.com/press/2007/12/17/how-to-enable-php-error-logging-via-htaccess/" target="_blank">Complete Information</a></p>
<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2009/03/13/php-configuration-inside-httpdconf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Compiling PHP 5.2.x / cannot find -lltdl</title>
		<link>http://blog.nataprawira.com/tech/2009/02/26/compiling-php-52x-cannot-find-lltdl/</link>
		<comments>http://blog.nataprawira.com/tech/2009/02/26/compiling-php-52x-cannot-find-lltdl/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 10:35:11 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[BASH]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[cannot find -lltdl]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=41</guid>
		<description><![CDATA[

 When compiling PHP from source, some of the CentOS users reported that they getting errors like below:

/usr/bin/ld: cannot find -lltdl
collect2: ld returned 1 exit status

What you need to do, is just follow the below steps.

Verify that the libtool and libtool-ltdl packages are installed.
Symlink libltdl.so to libltdl.so.x.x.x

If libtool and libtool-ltdl already exist, you may go [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F02%2F26%2Fcompiling-php-52x-cannot-find-lltdl%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F02%2F26%2Fcompiling-php-52x-cannot-find-lltdl%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<hr size="1" /><!-- / icon and title --> <!-- message -->When compiling PHP from source, some of the CentOS users reported that they getting errors like below:</p>
<div style="margin: 5px 20px 20px">
<pre style="border: 1px inset;margin: 0px;padding: 6px;width: 640px;height: 50px;text-align: left"><strong>/usr/bin/ld: cannot find -lltdl
collect2: ld returned 1 exit status</strong></pre>
</div>
<p>What you need to do, is just follow the below steps.</p>
<ol>
<li><strong>Verify that the libtool and libtool-ltdl packages are installed.</strong></li>
<li><strong>Symlink libltdl.so to libltdl.so.x.x.x</strong></li>
</ol>
<p>If libtool and libtool-ltdl already exist, you may go to Step Two.<br />
<strong> Step One</strong></p>
<div style="margin: 5px 20px 20px">
<pre style="border: 1px inset;margin: 0px;padding: 6px;width: 640px;height: 34px;text-align: left">[root@banzaibill ~]# <strong>yum install libtool-ltdl libtool</strong></pre>
</div>
<p>Now you have <strong>libtool</strong> installed. To check it out, do:</p>
<div style="margin: 5px 20px 20px">
<pre style="border: 1px inset;margin: 0px;padding: 6px;width: 640px;height: 34px;text-align: left">[root@banzaibill ~]# <strong>yum info libtool*</strong></pre>
</div>
<p><strong> Step Two</strong></p>
<p>PHP looks for the libltdl library only at <strong>/usr/lib/libltdl.so</strong></p>
<p>The symlink to this file is not included in the libtool packages. Do below commands:</p>
<div style="margin: 5px 20px 20px">
<pre style="border: 1px inset;margin: 0px;padding: 6px;width: 640px;height: 50px;text-align: left">[root@banzaibill ~]# <strong>cd /usr/lib</strong>
[root@banzaibill lib]# <strong>ln -s libltdl.so.3.1.4 libltdl.so</strong></pre>
</div>
<p>And that&#8217;s it. PHP should configure and compile without error.</p>
<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2009/02/26/compiling-php-52x-cannot-find-lltdl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to protect your website using simple PHP scripts</title>
		<link>http://blog.nataprawira.com/tech/2009/02/20/how-to-protect-your-website-using-simple-php-scripts/</link>
		<comments>http://blog.nataprawira.com/tech/2009/02/20/how-to-protect-your-website-using-simple-php-scripts/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 04:51:10 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Protection]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=36</guid>
		<description><![CDATA[

Just put below on your top line of the scripts :
$ips = array(&#8221;127.0.0.1&#8243;,&#8221;aaa.bbb.ccc&#8221;,&#8221;xxx.yyy.zzz&#8221;);
$userip = $_SERVER['REMOTE_ADDR'];
foreach ($ips as $ip) {
if (!preg_match(&#8221;/$ip/i&#8221;, $userip)) {
echo &#8220;Access Denied!&#8221;;
exit;
}
}
Notes:
$ips is the allowed IP address range
Other way, you can use .htaccess to protect directories/files.
]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F02%2F20%2Fhow-to-protect-your-website-using-simple-php-scripts%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F02%2F20%2Fhow-to-protect-your-website-using-simple-php-scripts%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p>Just put below on your top line of the scripts :</p>
<p><strong>$ips = array(&#8221;127.0.0.1&#8243;,&#8221;aaa.bbb.ccc&#8221;,&#8221;xxx.yyy.zzz&#8221;);<br />
$userip = $_SERVER['REMOTE_ADDR'];<br />
foreach ($ips as $ip) {<br />
if (!preg_match(&#8221;/$ip/i&#8221;, $userip)) {<br />
echo &#8220;Access Denied!&#8221;;<br />
exit;<br />
}<br />
}</strong></p>
<p><span style="text-decoration: underline">Notes</span>:<br />
$ips is the allowed IP address range</p>
<p>Other way, you can use .htaccess to protect directories/files.</p>
<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2009/02/20/how-to-protect-your-website-using-simple-php-scripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
