<?xml version="1.0" encoding="ISO-8859-1"?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title>ZemHost Forums - Useful Scripts</title>
		<link>http://www.zemhost.com/forums/</link>
		<description>Have a useful script that you like? Share it with everybody else here.</description>
		<language>en</language>
		<lastBuildDate>Thu, 09 Sep 2010 20:58:04 GMT</lastBuildDate>
		<generator>vBulletin</generator>
		<ttl>60</ttl>
		<image>
			<url>http://www.zemhost.com/forums/images/misc/rss.png</url>
			<title>ZemHost Forums - Useful Scripts</title>
			<link>http://www.zemhost.com/forums/</link>
		</image>
		<item>
			<title><![CDATA[[PHP]recursive_files]]></title>
			<link>http://www.zemhost.com/forums/threads/4055-PHP-recursive_files?goto=newpost</link>
			<pubDate>Tue, 07 Sep 2010 13:40:25 GMT</pubDate>
			<description><![CDATA[PHP: 
--------- 
<?php 
/** 
 * Loops through every folder from the specified path and lists the files with full path to. 
 *  
 * @author	Dan 
 *...]]></description>
			<content:encoded><![CDATA[<div><div class="bbcode_container">
	<div class="bbcode_description">PHP Code:</div>
	<hr /><code class="bbcode_code"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/**<br />&nbsp;*&nbsp;Loops&nbsp;through&nbsp;every&nbsp;folder&nbsp;from&nbsp;the&nbsp;specified&nbsp;path&nbsp;and&nbsp;lists&nbsp;the&nbsp;files&nbsp;with&nbsp;full&nbsp;path&nbsp;to.<br />&nbsp;*&nbsp;<br />&nbsp;*&nbsp;@author&nbsp;&nbsp;&nbsp;&nbsp;Dan<br />&nbsp;*&nbsp;@param&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;&nbsp;&nbsp;&nbsp;$path&nbsp;&nbsp;&nbsp;&nbsp;path&nbsp;to&nbsp;scanned&nbsp;folder<br />&nbsp;*&nbsp;@return&nbsp;&nbsp;&nbsp;&nbsp;array&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;path&nbsp;to&nbsp;each&nbsp;file<br />&nbsp;*/<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">recursive_files</span><span style="color: #007700">(</span><span style="color: #0000BB">$path</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$path&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">str_ireplace</span><span style="color: #007700">(</span><span style="color: #DD0000">'//'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'/'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$path</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">is_dir</span><span style="color: #007700">(</span><span style="color: #0000BB">$path</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$files&nbsp;</span><span style="color: #007700">=&nbsp;array();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$dirHandle&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">opendir</span><span style="color: #007700">(</span><span style="color: #0000BB">$path</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;(</span><span style="color: #0000BB">$file&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">readdir</span><span style="color: #007700">(</span><span style="color: #0000BB">$dirHandle</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;((</span><span style="color: #0000BB">$file&nbsp;</span><span style="color: #007700">!=&nbsp;</span><span style="color: #DD0000">'.'</span><span style="color: #007700">)&nbsp;&amp;&amp;&nbsp;(</span><span style="color: #0000BB">$file&nbsp;</span><span style="color: #007700">!=&nbsp;</span><span style="color: #DD0000">'..'</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$file&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$path&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">'/'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$file</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$files&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_merge</span><span style="color: #007700">(</span><span style="color: #0000BB">$files</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">recursive_files</span><span style="color: #007700">(</span><span style="color: #0000BB">$file</span><span style="color: #007700">));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">$files</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;if&nbsp;(</span><span style="color: #0000BB">is_file</span><span style="color: #007700">(</span><span style="color: #0000BB">$path</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;array(</span><span style="color: #0000BB">$path</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;array();<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></code><hr />
</div> *<b>Dan</b> is my real name, that's why it's author is &quot;Dan&quot;. I'm not ripping any PHP snippets, I like to do anything from scratch.</div>

 ]]></content:encoded>
			<category domain="http://www.zemhost.com/forums/forums/11-Useful-Scripts">Useful Scripts</category>
			<dc:creator>DunnKz</dc:creator>
			<guid isPermaLink="true">http://www.zemhost.com/forums/threads/4055-PHP-recursive_files</guid>
		</item>
		<item>
			<title><![CDATA[[PHP] Gradient function]]></title>
			<link>http://www.zemhost.com/forums/threads/4036-PHP-Gradient-function?goto=newpost</link>
			<pubDate>Sat, 04 Sep 2010 08:11:46 GMT</pubDate>
			<description><![CDATA[Hello! I'm really bored so I decided to do something nice. I just thought on doing a gradient generator. Here it is: 
 
Code: 
--------- 
<?php 
/**...]]></description>
			<content:encoded><![CDATA[<div>Hello! I'm really bored so I decided to do something nice. I just thought on doing a gradient generator. Here it is:<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">&lt;?php<br />
/**<br />
&nbsp;* Generates a gradient with &lt;code&gt;$stages&lt;/code&gt;, using colors &lt;code&gt;$from&lt;/code&gt; and &lt;code&gt;$to&lt;/code&gt;.<br />
&nbsp;*<br />
&nbsp;* @param&nbsp; &nbsp; &nbsp; &nbsp; String&nbsp; &nbsp; &nbsp; &nbsp; $from&nbsp; &nbsp; &nbsp; &nbsp; begin<br />
&nbsp;* @param&nbsp; &nbsp; &nbsp; &nbsp; String&nbsp; &nbsp; &nbsp; &nbsp; $to&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end<br />
&nbsp;* @param&nbsp; &nbsp; &nbsp; &nbsp; int&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $stages&nbsp; &nbsp; &nbsp; &nbsp; number of stages<br />
&nbsp;* @todo&nbsp; &nbsp; &nbsp; &nbsp; test and bug-fix(if any)<br />
&nbsp;*<br />
&nbsp;* @author&nbsp; &nbsp; &nbsp; &nbsp; Dan &lt;DunnKz, from ZemHost community&gt;<br />
&nbsp;*/<br />
function gradient($from, $to, $stages) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; $hexdec_color = function($color) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $color = str_ireplace('#', '', $color);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $color = str_split($color, 2);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $_color['r'] = hexdec($color[0]);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $_color['g'] = hexdec($color[1]);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $_color['b'] = hexdec($color[2]);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return $_color;<br />
&nbsp; &nbsp; &nbsp; &nbsp; };<br />
&nbsp; &nbsp; &nbsp; &nbsp; $dechex_color = function ($color) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $color['r'] = dechex($color['r']);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $color['g'] = dechex($color['g']);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $color['b'] = dechex($color['b']);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (strlen($color['r']) &lt; 2) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $color['r'] = '0' . $color['r'];<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (strlen($color['g']) &lt; 2) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $color['g'] = '0' . $color['g'];<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (strlen($color['b']) &lt; 2) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $color['b'] = '0' . $color['b'];<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return '#' . $color['r'] . $color['g'] . $color['b'];<br />
&nbsp; &nbsp; &nbsp; &nbsp; };<br />
&nbsp; &nbsp; &nbsp; &nbsp; $from = $hexdec_color($from);<br />
&nbsp; &nbsp; &nbsp; &nbsp; $to = $hexdec_color($to);<br />
&nbsp; &nbsp; &nbsp; &nbsp; $R_stage = floor(($from['r'] - $to['r']) / $stages);<br />
&nbsp; &nbsp; &nbsp; &nbsp; $G_stage = floor(($from['g'] - $to['g']) / $stages);<br />
&nbsp; &nbsp; &nbsp; &nbsp; $B_stage = floor(($from['b'] - $to['b']) / $stages);<br />
&nbsp; &nbsp; &nbsp; &nbsp; $_gradient[0] = $from;<br />
&nbsp; &nbsp; &nbsp; &nbsp; $_gradient[$stages - 1] = $to;<br />
&nbsp; &nbsp; &nbsp; &nbsp; for ($i = 1; $i &lt; $stages - 1; $i++) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $_gradient[$i]['r'] = $_gradient[$i - 1]['r'] - $R_stage;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $_gradient[$i]['g'] = $_gradient[$i - 1]['g'] - $G_stage;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $_gradient[$i]['b'] = $_gradient[$i - 1]['b'] - $B_stage;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ($_gradient[$i]['r'] &lt; 0) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $_gradient[$i]['r'] = 0;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ($_gradient[$i]['r'] &gt; 255) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $_gradient[$i]['r'] = 255;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ($_gradient[$i]['g'] &lt; 0) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $_gradient[$i]['g'] = 0;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ($_gradient[$i]['g'] &gt; 255) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $_gradient[$i]['g'] = 255;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ($_gradient[$i]['b'] &lt; 0) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $_gradient[$i]['b'] = 0;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ($_gradient[$i]['b'] &gt; 255) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $_gradient[$i]['b'] = 255;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; for ($i = 0; $i &lt; $stages; $i++) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $gradient[$i] = $dechex_color($_gradient[$i]);<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; return $gradient;<br />
}<br />
/*<br />
&nbsp;* Example 1<br />
&nbsp;*/<br />
$gradient = gradient('#0000ff', '#ff0000', 50);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Nice blue -&gt; red gradient using 50 stages.<br />
foreach ($gradient as $color) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; echo '&lt;div style=&quot;background-color: ' . $color .'; width: 50px; height: 10px; display: block;&quot;&gt;&lt;/div&gt;';<br />
}<br />
/*<br />
&nbsp;* Example 2<br />
&nbsp;*/<br />
$stringArray = str_split('ZemHost');<br />
$len = count($stringArray);<br />
$gradient = gradient('#0000ff', '#ff0000', $len);<br />
for ($i = 0; $i &lt; $len; $i++) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; echo '[COLOR=&quot;'. $gradient[$i] .'&quot;]' . $stringArray[$i] . '[/COLOR]';<br />
}<br />
?&gt;</code><hr />
</div> Example 2: <font color="#0000ff">Z</font><font color="#2500db">e</font><font color="#4a00b7">m</font><font color="#6f0093">H</font><font color="#94006f">o</font><font color="#b9004b">s</font><font color="#ff0000">t</font></div>

 ]]></content:encoded>
			<category domain="http://www.zemhost.com/forums/forums/11-Useful-Scripts">Useful Scripts</category>
			<dc:creator>DunnKz</dc:creator>
			<guid isPermaLink="true">http://www.zemhost.com/forums/threads/4036-PHP-Gradient-function</guid>
		</item>
		<item>
			<title><![CDATA[[PHP] Useful functions related to IPs (ipToInt, is_ipInRange)]]></title>
			<link>http://www.zemhost.com/forums/threads/4035-PHP-Useful-functions-related-to-IPs-%28ipToInt-is_ipInRange%29?goto=newpost</link>
			<pubDate>Sat, 04 Sep 2010 06:45:15 GMT</pubDate>
			<description><![CDATA[Hello guys! 
I hadn't posted a good thing for ages, so I just thought I should give you my functions that I use for IPs related problems. 
 
 
Code:...]]></description>
			<content:encoded><![CDATA[<div>Hello guys!<br />
I hadn't posted a good thing for ages, so I just thought I should give you my functions that I use for IPs related problems.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">&lt;?php<br />
/**<br />
&nbsp;* Converts an IP to an integer.<br />
&nbsp;* <br />
&nbsp;* @param&nbsp; &nbsp; &nbsp; &nbsp; String&nbsp; &nbsp; &nbsp; &nbsp; $ip&nbsp; &nbsp; &nbsp; &nbsp; ip, ready for conversion<br />
&nbsp;* @return&nbsp; &nbsp; &nbsp; &nbsp; int&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; requested IP to int(it's size being 4 classes * 3 digits each class = 12)<br />
&nbsp;* @todo&nbsp; &nbsp; &nbsp; &nbsp; There's a little problem. 2^31 - 1 (maxint) has 10 digits, but this has 12 digits. :(<br />
&nbsp;*<br />
&nbsp;* @author&nbsp; &nbsp; &nbsp; &nbsp; Dan &lt;DunnKz, from ZemHost community&gt;<br />
&nbsp;*/<br />
function ipToInt($ip) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; $ip = explode('.', $ip);<br />
&nbsp; &nbsp; &nbsp; &nbsp; while (strlen($ip[0]) &lt; 3) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ip[0] = '0' . $ip[0];<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; while (strlen($ip[1]) &lt; 3) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ip[1] = '0' . $ip[1];<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; while (strlen($ip[2]) &lt; 3) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ip[2] = '0' . $ip[2];<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; while (strlen($ip[3]) &lt; 3) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ip[3] = '0' . $ip[3];<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; return $ip[0] . $ip[1] . $ip[2] . $ip[3];<br />
}<br />
<br />
/**<br />
&nbsp;* Checks if an &lt;code&gt;$ip&lt;/code&gt; is in range(&lt;code&gt;$from&lt;/to&gt; to &lt;code&gt;$to&lt;/code&gt;).<br />
&nbsp;* @param&nbsp; &nbsp; &nbsp; &nbsp; String&nbsp; &nbsp; &nbsp; &nbsp; $from<br />
&nbsp;* @param&nbsp; &nbsp; &nbsp; &nbsp; String&nbsp; &nbsp; &nbsp; &nbsp; $to<br />
&nbsp;* @param&nbsp; &nbsp; &nbsp; &nbsp; String&nbsp; &nbsp; &nbsp; &nbsp; $ip<br />
&nbsp;* @return&nbsp; &nbsp; &nbsp; &nbsp; bool&nbsp; &nbsp; &nbsp; &nbsp; &lt;code&gt;true&lt;/code&gt; if yes, else &lt;code&gt;false&lt;/code&gt;<br />
&nbsp;* @uses&nbsp; &nbsp; &nbsp; &nbsp; &lt;code&gt;ipToInt($ip)&lt;/code&gt;<br />
&nbsp;*<br />
&nbsp;* @author&nbsp; &nbsp; &nbsp; &nbsp; Dan &lt;DunnKz, from ZemHost community&gt;<br />
&nbsp;*/<br />
function is_ipInRange($from, $to, $ip) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; $from = ipToInt($from);<br />
&nbsp; &nbsp; &nbsp; &nbsp; $to = ipToInt($to);<br />
&nbsp; &nbsp; &nbsp; &nbsp; if ($from &gt; $to) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $_ = $to;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $to = $from;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $from = $_;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; $ip = ipToInt($ip);<br />
&nbsp; &nbsp; &nbsp; &nbsp; return (($ip &lt;= $to) &amp;&amp; ($ip &gt;= $from));<br />
}<br />
<br />
/*<br />
&nbsp;* Examples<br />
&nbsp;*/<br />
echo is_ipInRange('127.0.0.255', '127.0.0.0', '127.0.0.1') ? 'Yes' : 'No';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Outputs &quot;Yes&quot;<br />
echo is_ipInRange('127.0.0.255', '127.0.0.0', '127.0.0.255') ? 'Yes' : 'No';&nbsp; &nbsp; &nbsp; &nbsp; // Outputs &quot;Yes&quot;<br />
echo is_ipInRange('126.0.0.255', '126.0.0.0', '127.0.0.1') ? 'Yes' : 'No';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Outputs &quot;No&quot;<br />
echo is_ipInRange('126.0.0.255', '128.0.0.0', '127.0.0.1') ? 'Yes' : 'No';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Outputs &quot;Yes&quot;<br />
?&gt;</code><hr />
</div> This can be used for ban IP systems, if requested, I'll post here one. :D<br />
<br />
I'm waiting for feedback.</div>

 ]]></content:encoded>
			<category domain="http://www.zemhost.com/forums/forums/11-Useful-Scripts">Useful Scripts</category>
			<dc:creator>DunnKz</dc:creator>
			<guid isPermaLink="true">http://www.zemhost.com/forums/threads/4035-PHP-Useful-functions-related-to-IPs-%28ipToInt-is_ipInRange%29</guid>
		</item>
		<item>
			<title><![CDATA[[C] Little Timer]]></title>
			<link>http://www.zemhost.com/forums/threads/4023-C-Little-Timer?goto=newpost</link>
			<pubDate>Mon, 30 Aug 2010 10:34:36 GMT</pubDate>
			<description>This is a little timer program I wrote, a clone of sleep (in GNU coreutils) but it displays more information. It uses the same argument format as...</description>
			<content:encoded><![CDATA[<div>This is a little timer program I wrote, a clone of sleep (in GNU coreutils) but it displays more information. It uses the same argument format as sleep. It's not really a script (but a program), but there's no more suitable places to post it.<br />
It's untested under any environment other than my Gentoo. It uses a nonstandard sleep() function that may or may not exist in your C library. (It exists in glibc.) And a C99-compliant compiler is required.<br />
For any results that it creates, I'm not liable. (For example, if you overcook your dinner because the timing does not work, you won't get a free lunch from me. :D )<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">// timer.c -- sleep clone with more information displayed<br />
// Richard Grenville<br />
// August 30th, 2010<br />
// License: GPLv3 (or a newer version)<br />
// Tested with gcc 4.4.4 under Gentoo amd64<br />
#include&nbsp; &nbsp; &nbsp; &nbsp; &lt;stdio.h&gt;<br />
#include&nbsp; &nbsp; &nbsp; &nbsp; &lt;stdlib.h&gt;<br />
#include&nbsp; &nbsp; &nbsp; &nbsp; &lt;limits.h&gt;<br />
<br />
const char *MSG[] = {<br />
&nbsp; &nbsp; &nbsp; &nbsp; [0] = &quot;Usage: timer &lt;waiting time (s/m/h/d) ...&gt;\n&quot;<br />
};<br />
<br />
inline void prttime(const long time, const long totaltime) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; printf(&quot;%2ld:%2ld:%2ld (%4.1f%%) left.\n&quot;, time / 3600, time % 3600 / 60<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , time % 60, (double) time / totaltime * 100);<br />
}<br />
<br />
long argproc(const char *str);<br />
<br />
int main(int argc, char *argv[]) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; long time, totaltime = 0;<br />
&nbsp; &nbsp; &nbsp; &nbsp; long i;<br />
&nbsp; &nbsp; &nbsp; &nbsp; char **argptr, **argend;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; if(1 == argc) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fputs(MSG[0], stderr);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return -1;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; for(argptr = argv + 1, argend = argv + argc<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ; argptr &lt; argend; argptr++) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if((i = argproc(*argptr)) &lt; 0) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(-1 == i)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fputs(MSG[0], stderr);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return i;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; totaltime += i;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; time = totaltime;<br />
&nbsp; &nbsp; &nbsp; &nbsp; while(time-- &gt; 0) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // printf(&quot;Time: %ld\n&quot;, time);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(sleep(1))<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return 1;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; prttime(time, totaltime);<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; return 0;<br />
}<br />
<br />
long argproc(const char *str) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; char *endptr, **pendptr = &amp;endptr;<br />
&nbsp; &nbsp; &nbsp; &nbsp; double convval;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; convval = strtod(str, pendptr);<br />
&nbsp; &nbsp; &nbsp; &nbsp; if('\0' == *endptr) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(convval &gt; LONG_MAX)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return -2;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return (long) convval;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; if('\0' != *(endptr + 1))<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return -1;<br />
&nbsp; &nbsp; &nbsp; &nbsp; switch(*endptr) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 's':&nbsp; &nbsp; &nbsp; &nbsp; break;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 'm':&nbsp; &nbsp; &nbsp; &nbsp; convval *= 60;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 'h':&nbsp; &nbsp; &nbsp; &nbsp; convval *= 3600;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 'd':&nbsp; &nbsp; &nbsp; &nbsp; convval *= 3600 * 24;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; if(convval &gt; LONG_MAX)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return -2;<br />
&nbsp; &nbsp; &nbsp; &nbsp; return (long) convval;<br />
}</code><hr />
</div> </div>

 ]]></content:encoded>
			<category domain="http://www.zemhost.com/forums/forums/11-Useful-Scripts">Useful Scripts</category>
			<dc:creator>RichardGv</dc:creator>
			<guid isPermaLink="true">http://www.zemhost.com/forums/threads/4023-C-Little-Timer</guid>
		</item>
		<item>
			<title>Simple Web Server in Lua (LuaSocket)</title>
			<link>http://www.zemhost.com/forums/threads/4018-Simple-Web-Server-in-Lua-%28LuaSocket%29?goto=newpost</link>
			<pubDate>Wed, 25 Aug 2010 02:51:48 GMT</pubDate>
			<description><![CDATA[Using Lua for Windows, I've designed a simple web server in Lua. It is a little glitchy and I had a really good, secure copy of it that even allowed...]]></description>
			<content:encoded><![CDATA[<div>Using Lua for Windows, I've designed a simple web server in Lua. It is a little glitchy and I had a really good, secure copy of it that even allowed binary files to be safely transferred, but I lost it.<br />
<br />
To use this code, you'll need:<ul><li>Lua for Windows</li>
<li>LuaSocket (add-on comes with Lua for Windows)</li>
<li>A Browser!</li>
<li>Available folder for files</li>
</ul><br />
Simply running the following code sets up a simple server. It will tell you what port you need to connect to. When it tells you,  you must connect to the port via localhost or 127.0.0.1. <br />
<br />
<b>server.lua</b><br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">-- load namespace<br />
local socket = require(&quot;socket&quot;)<br />
-- create a TCP socket and bind it to the local host, at any port<br />
local server = assert(socket.bind(&quot;localhost&quot;, 1337))<br />
-- find out which port the OS chose for us<br />
local ip, port = server:getsockname()<br />
-- print a message informing what's up<br />
print(&quot;PORT: &quot; .. port)<br />
print(&quot;IP: &quot; .. ip)<br />
-- loop forever waiting for clients<br />
while true do<br />
&nbsp; -- wait for a connection from any client<br />
&nbsp; local client = server:accept()<br />
&nbsp; -- make sure we don't block waiting for this client's line<br />
&nbsp; --client:settimeout(10)<br />
&nbsp; -- receive the line<br />
&nbsp; local line, err = client:receive()<br />
&nbsp; -- if there was no error, send it back to the client<br />
&nbsp; if not err then<br />
&nbsp; &nbsp; &nbsp; &nbsp; print(&quot;Sent.&quot;)<br />
&nbsp; &nbsp; &nbsp; &nbsp; local content =<br />
[[&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;Hi&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;h1&gt;Hi&lt;/h1&gt;<br />
It works.<br />
&lt;/body&gt;<br />
&lt;/html&gt;]]<br />
&nbsp; &nbsp; &nbsp; &nbsp; local sendthis =<br />
[[HTTP/1.1 200 OK<br />
Content-type: text/html<br />
Content-length: ]] .. string.len(content) .. [[<br />
<br />
<br />
]] .. content<br />
&nbsp; &nbsp; &nbsp; &nbsp; sendthis = string.gsub(sendthis,&quot;\n&quot;,&quot;\r\n&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; client:send(sendthis)<br />
&nbsp; end<br />
&nbsp; -- done with client, close the object<br />
&nbsp; client:close()<br />
end</code><hr />
</div> To connect to it, use <a href="http://localhost:1337/" target="_blank" rel="nofollow">http://localhost:1337/</a> (or a different port) OR <a href="http://127.0.0.1:1337/" target="_blank" rel="nofollow">http://127.0.0.1:1337/</a><br />
<br />
To launch the server, use this batch script to launch it via command prompt. Lua for Windows will register the &quot;lua&quot; command when installed.<br />
<br />
<b>start.bat</b><br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">@echo off<br />
lua server.lua<br />
pause &gt; nul</code><hr />
</div> If you want others computers to connect to this port, you must have port forwarding technologies available to you. If you connect to the internet via a wireless router, you should look at port forwarding.<br />
<br />
This is for anyone who's interested in how basic web servers work. I hope you improve this code eventually :D</div>

 ]]></content:encoded>
			<category domain="http://www.zemhost.com/forums/forums/11-Useful-Scripts">Useful Scripts</category>
			<dc:creator>Ozzypig</dc:creator>
			<guid isPermaLink="true">http://www.zemhost.com/forums/threads/4018-Simple-Web-Server-in-Lua-%28LuaSocket%29</guid>
		</item>
	</channel>
</rss>
