<?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>1-800-HOSTING Blog &#187; PHP</title>
	<atom:link href="http://blog.800hosting.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.800hosting.com</link>
	<description>Inside 1-800-HOSTING</description>
	<lastBuildDate>Wed, 02 Nov 2011 17:00:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>PHP Script Tips and Resources</title>
		<link>http://blog.800hosting.com/2010/02/php-script-tips-and-resources/</link>
		<comments>http://blog.800hosting.com/2010/02/php-script-tips-and-resources/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 17:30:41 +0000</pubDate>
		<dc:creator>John Cunningham</dc:creator>
				<category><![CDATA[Fun Stuff]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[free php scripts]]></category>
		<category><![CDATA[google crawler]]></category>
		<category><![CDATA[googlebot]]></category>
		<category><![CDATA[joomla]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[osCommerce]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[website]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://blog.800hosting.com/?p=1205</guid>
		<description><![CDATA[PHP is a language absolutely made for websites. PHP code can be inserted into an html page to enable dynamic creation. Many content management systems like Drupal, Joomla, and osCommerce  use PHP together with MySQL to build webpages. You can use PHP to detect crawling activity, rotate images/banners, and process forms. Here is an example [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://static.php.net/www.php.net/images/php.gif" alt="php" /> PHP is a language absolutely made for websites. <a title="php" href="http://php.net/" target="_blank">PHP</a> code can be inserted into an html page to enable dynamic creation. Many content management systems like Drupal, Joomla, and osCommerce  use PHP together with MySQL to build webpages.<span id="more-1205"></span></p>
<p>You can use PHP to detect crawling activity, rotate images/banners, and process forms. Here is an example of code that will email you whenever Google crawler Googlebot visits your page by detecting the useragent. You could expand the code to include other crawlers, add date and time stamp, and validate the IP to exclude impostors. I left that stuff out for simplicity and because you can  get that info from your webstats/logs. Just copy and paste this code in your web page to try it out. Note that the page may have to end with .php file extension to work, it depends on how your web server is setup.</p>
<blockquote><p>&lt;?<br />
if(eregi(&#8220;Googlebot&#8221;,$_SERVER['HTTP_USER_AGENT'])){</p>
<p>//put your email address below<br />
$address=youname@yourdomain.com;<br />
$subject=&#8221;Google visited &#8220;.$_SERVER[’HTTP_HOST’];<br />
$message=&#8221;Googlebot visited today.&#8221;;<br />
mail($address, $subject, $message);<br />
}<br />
?&gt;</p></blockquote>
<p>Here is an example of how to display  random images in a web page, it will pick one of the three banners each time the page loads. You could easily add more cases here or change the img src line to make this a random text function.</p>
<blockquote><p>&lt;?<br />
$randomimage = Rand (1,3) ;</p>
<p>//put your image name at bannerx<br />
switch ($randomimage)<br />
{<br />
case 1:<br />
&#8220;banner1&#8243;;<br />
break;</p>
<p>case 2:<br />
&#8220;banner2&#8243;;<br />
break;</p>
<p>case 3:<br />
&#8220;banner3&#8243;;<br />
break;<br />
}</p>
<p>echo &#8216;&lt;img src=&#8221;&#8216;$randomimage.&#8217;&#8221; border=0&gt;&#8217;;</p>
<p>?&gt;</p></blockquote>
<p>Another cool thing you can do is filter form data to by blocking bad words, banning ip addresses, and setting a timer with a cookie. There is nothing worse than having your website form spammed. You can get the visitor&#8217;s IP address with a built in php function and then check it against a list of bad IP addresses you have stored in a list called an <em>array</em>. You can modify this to include words by replacing the IP addresses with words. This is useful if there is a relatively small number of abusers. In the case of larger numbers, blocking at the server level using <a title="iptables wikipedia definition" href="http://en.wikipedia.org/wiki/Iptables" target="_blank">iptables</a> or a firewall may work better for you.</p>
<p>Here is the code for blocking IPs and you can add more IPs to the array if needed:</p>
<blockquote><p>&lt;?<br />
$banned_ip_addresses = array(&#8217;4.2.5.5&#8242;, &#8217;64.43.67.19&#8242;, &#8217;207.22.32.152&#8242;);</p>
<p>if(in_array($_SERVER['REMOTE_ADDR'], $banned_ip_addresses))<br />
{<br />
echo &#8220;You are banned.&#8221;;<br />
} else {<br />
continue with form processing&#8230;<br />
}</p></blockquote>
<p>If you are having problems with abusive surfers filling out your forms with constantly changing ip addresses, you can stop them by adding a cookie. A cookie is a small piece of code sent to the user&#8217;s pc to identify them.  Note that not all browsers will accept cookies, but most will. Once the cookie is set, you check for the existence of it in your form processing. Here is an example:</p>
<blockquote><p>//this sets time to 7200 seconds, 2 hours<br />
&lt;?<br />
setcookie(&#8220;userx&#8221;, &#8220;cookie1&#8243;, time()+7200);<br />
?&gt;</p>
<p>Then add the code below to find out if this person has been on your page before:</p>
<p>&lt;?<br />
if (isset($_COOKIE1["userx"])){<br />
echo &#8220;You have already filled out this form recently&#8221;;</p>
<p>} else {<br />
continue with form processing&#8230;<br />
}<br />
?&gt;</p></blockquote>
<p>There is a plethora of PHP support websites on the Internet. My longtime favorite is  <a title="php freaks forum" href="http://www.phpfreaks.com/forums/" target="_blank">PHP Freaks Forum</a> where you can post  technical questions and read responses. Another good one is the <a title="digital point php forum" href="http://forums.digitalpoint.com/forumdisplay.php?f=37" target="_blank">Digital Point PHP Forum</a>. If you are looking for scripts then visit <a title="hotscripts" href="http://www.hotscripts.com/category/php/scripts-programs/" target="_blank">Hotscripts</a>, where you will find many, some free and some paid. Also check out <a title="free scripts directory" href="http://gscripts.net/" target="_blank">Free Scripts Directory</a>,  <a title="script repository" href="http://www.sitescripts.com/PHP/" target="_blank">Script Repository</a>, and <a title="php resource index" href="http://php.resourceindex.com/Complete_Scripts/" target="_blank">PHP Resource Index</a>. They have scripts for: counters, auctions, voting, calculators, searching, support ticketing, etc.</p>
<p>PHP works fine on both Linux and Windows systems. If you have a Linux box then chances are good that it is already installed; if not, visit <a title="php" href="http://php.net/" target="_blank">php.net</a> to download it. PHP is not standard on Windows but it can be installed. If you need technical support we can help you with installing or upgrading.</p>
<p>PHP is very powerful. In an upcoming post I will explain how to speed it up using accelerators, pull data from a database, write it to a webpage, and add functionality using extensions.</p>
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li><a href="http://blog.800hosting.com/2011/07/workstation-backup-solutions-pt-3-redundancy/" title="Workstation Backup Solutions Pt. 3: Redundancy">Workstation Backup Solutions Pt. 3: Redundancy</a></li><li><a href="http://blog.800hosting.com/2011/07/workstation-backup-solutions-pt-2-methods-retention/" title=" Workstation Backup Solutions Pt. 2: Methods &amp; Retention"> Workstation Backup Solutions Pt. 2: Methods &amp; Retention</a></li><li><a href="http://blog.800hosting.com/2011/06/workstation-backup-solutions-pt-1-having-one/" title="Workstation Backup Solutions Pt. 1: Having One">Workstation Backup Solutions Pt. 1: Having One</a></li><li><a href="http://blog.800hosting.com/2009/12/drupal-free-website-building-tool/" title="Drupal &#8211; Free Website Building Tool">Drupal &#8211; Free Website Building Tool</a></li><li><a href="http://blog.800hosting.com/2009/05/linux-shell-insights-volume-2/" title="Linux Shell Insights: Volume 2">Linux Shell Insights: Volume 2</a></li><li><a href="http://blog.800hosting.com/2009/05/linux-shell-insights-volume-1/" title="Linux Shell Insights: Volume 1">Linux Shell Insights: Volume 1</a></li><li><a href="http://blog.800hosting.com/2011/08/mysql-error-in-the-errmsg-sys-file/" title="MySQL Error in the errmsg.sys file">MySQL Error in the errmsg.sys file</a></li><li><a href="http://blog.800hosting.com/2010/01/mysql-version-6-preview/" title="MySQL Version 6 Preview">MySQL Version 6 Preview</a></li><li><a href="http://blog.800hosting.com/2009/12/a-little-security-goes-a-loooong-way/" title="A Little Security Goes a LOOOONG Way">A Little Security Goes a LOOOONG Way</a></li><li><a href="http://blog.800hosting.com/2009/11/linux-tip-setting-up-key-based-authentication/" title="Linux Tip: Setting up key-based authentication.">Linux Tip: Setting up key-based authentication.</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://blog.800hosting.com/2010/02/php-script-tips-and-resources/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

