<?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>Ersin Acar &#187; function</title>
	<atom:link href="http://ersinacar.com/tag/function/feed" rel="self" type="application/rss+xml" />
	<link>http://ersinacar.com</link>
	<description>PHP and Web Technologies Freak</description>
	<lastBuildDate>Fri, 06 Jan 2012 14:19:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to get file extensions in PHP</title>
		<link>http://ersinacar.com/how-to-get-file-extensions-in-php_123.html</link>
		<comments>http://ersinacar.com/how-to-get-file-extensions-in-php_123.html#comments</comments>
		<pubDate>Thu, 21 May 2009 09:22:22 +0000</pubDate>
		<dc:creator>Ersin Acar</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[count]]></category>
		<category><![CDATA[explode]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[preg]]></category>
		<category><![CDATA[preg_replace]]></category>
		<category><![CDATA[split]]></category>
		<category><![CDATA[strpos]]></category>
		<category><![CDATA[strrchr]]></category>

		<guid isPermaLink="false">http://ersinacar.com/?p=123</guid>
		<description><![CDATA[There are several methods get a file extension using PHP: &#60;? $filename = 'myfile.jpg'; &#160; // 1. The &#34;explode/end&#34; method $ext = end&#40;explode&#40;'.', $filename&#41;&#41;; &#160; // 2. The &#34;strrchr&#34; method $ext = substr&#40;strrchr&#40;$filename, '.'&#41;, 1&#41;; &#160; // 3. The &#34;strrpos&#34; method $ext = substr&#40;$filename, strrpos&#40;$filename, '.'&#41; + 1&#41;; &#160; // 4. The &#34;preg_replace&#34; method $ext [...]]]></description>
			<content:encoded><![CDATA[<p>There are several methods get a file extension using PHP:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #000088;">$filename</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'myfile.jpg'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// 1. The &quot;explode/end&quot; method</span>
<span style="color: #000088;">$ext</span> <span style="color: #339933;">=</span> <span style="color: #990000;">end</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// 2. The &quot;strrchr&quot; method</span>
<span style="color: #000088;">$ext</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strrchr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// 3. The &quot;strrpos&quot; method</span>
<span style="color: #000088;">$ext</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #339933;">,</span> <span style="color: #990000;">strrpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// 4. The &quot;preg_replace&quot; method</span>
<span style="color: #000088;">$ext</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/^.*\.([^.]+)$/D'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'$1'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// 5. The &quot;never use this&quot; method</span>
<span style="color: #666666; font-style: italic;">//   From: http://php.about.com/od/finishedphp1/qt/file_ext_PHP.htm</span>
<span style="color: #000088;">$exts</span> <span style="color: #339933;">=</span> <span style="color: #990000;">split</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;[/<span style="color: #000099; font-weight: bold;">\\</span>.]&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$n</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$exts</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ext</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$exts</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$n</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://ersinacar.com/how-to-get-file-extensions-in-php_123.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Determine whether an IP is within a certain range</title>
		<link>http://ersinacar.com/determine-whether-an-ip-is-within-a-certain-range_112.html</link>
		<comments>http://ersinacar.com/determine-whether-an-ip-is-within-a-certain-range_112.html#comments</comments>
		<pubDate>Sat, 16 May 2009 08:31:43 +0000</pubDate>
		<dc:creator>Ersin Acar</dc:creator>
				<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Add new tag]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[ip]]></category>
		<category><![CDATA[ip range]]></category>
		<category><![CDATA[range]]></category>

		<guid isPermaLink="false">http://ersinacar.com/?p=112</guid>
		<description><![CDATA[I spend a lot of time lurking in the channel # PHP (EFnet and freenode, please &#8211; no flame wars) and this issue is a frequently asked that the rule is a simple answer in the form of the use of strpos (), or best to ip2long () in a more than less than reply. [...]]]></description>
			<content:encoded><![CDATA[<p>
I spend a lot of time lurking in the channel # PHP (EFnet and freenode, please &#8211; no flame wars) and this issue is a frequently asked that the rule is a simple answer in the form of the use of strpos (), or best to ip2long () in a more than less than reply.</p>
<p>Unfortunately, although the people in the rule that an IP address is just an unsigned 32-bit integer, and is easy to determine, usually with $ _SERVER [ "REMOTE_ADDR"], where the real challenge &#8211; is in defining the range within which it must decide whether the IP address. IP ranges are usually divided into three categories (in increasing complexity):</p>
<p>         1. Wild Card: 192.168.10 .*<br />
         2. Start-end: 10.1.0.0-10.1.255.255<br />
         3. * CIDR: 172.16.1.0/24</p>
<p>      * Classless Inter-Domain Routing<br />
<span id="more-112"></span><br />
The wild card method, or &#8216;class&#8217;, lets you in the class A (10 .*.*.*), Class B (172.16 .*.*) or Class C (192.168.10 .*) levels granularity of the things we like in the old days (before the web decided to make the popular internet). But still, this is just not granular enough for practice.</p>
<p>Thus was born CIDR (yes, I&#8217;m talking about skipping the end of last start now). CIDR was on the concept that we really do not need to create networks to 8, 16, 24-bit boundaries, and we could be more granular by using an arbitrary number (from 2-30) to a series of networks. Details about why you can not use &#8220;31&#8243; beyond the scope of this article.</p>
<p>CIDR renaming of the former Class A, B and C networks / 8, / 16 and / 24, and reflects the left-most significant bits of the 32-bit IP address. Thus was born the possibility of very specific IP ranges in the form abcd / xx. However, part of the problem with this is that, although it succinctly describes the network beginning and end, the most normal mortal people could not decipher. CIDR addressing may also be in the form of a longer netmask, eg abcd/255.255.255.224</p>
<p>The simplified form of start-IP &#8211; IP in the end was just the place for mortals and is typically used by persons without networking background. There is also strong in the consumer broadband router, and especially in Microsoft Windows DHCP server.</p>
<p>To have declared, as a number, and hence that a network mask is, how can we use this knowledge to help us in determining whether an IP is in an area?</p>
<p>What this article will attempt to do if the design of algorithms for the verification of IP addresses easier.</p>
<p>Logically, Method 1 (the wildcard), the method can be easily 2 (start-end) through the use of setting start and end of the wildcard string and replaces the character &#8220;*&#8221; and 0 for the start and 255 for the end, for example, &#8220;192.168.10 .*&#8221; will &#8220;192.168.10.0-192.168.10.255&#8243; which (I hope) will be for everyone apparently.</p>
<p>We can then assess whether Method1 and Method2 in the same way. In this, we simply use the PHP function in ip2long () for all 3 values and a mathematical test start <= IP <= end.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">list</span> <span style="color: #009900;">&#40;</span>$ low<span style="color: #339933;">,</span> $ II<span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'-'</span><span style="color: #339933;">,</span> $<span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        $ Lower_dec <span style="color: #339933;">=</span> <span style="color: #990000;">ip2long</span> <span style="color: #009900;">&#40;</span>$ lower<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        $ Upper_dec <span style="color: #339933;">=</span> <span style="color: #990000;">ip2long</span> <span style="color: #009900;">&#40;</span>$ top<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        $ Ip_dec <span style="color: #339933;">=</span> <span style="color: #990000;">ip2long</span> <span style="color: #009900;">&#40;</span>$ ip<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>$ ip_dec<span style="color: #339933;">&gt;</span> <span style="color: #339933;">=</span> $ lower_dec<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span> <span style="color: #339933;">&amp;</span> <span style="color: #009900;">&#40;</span>$ ip_dec <span style="color: #339933;">&lt;=</span> $ upper_dec<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>We have, however, a complicating factor here &#8211; PHP does not do unsigned integer (32 bit) &#8211; which would be necessary for this math to work. We can do this by switching to negate floating point datatypes. PHP stores floating species as 64-bit and thus will have no problem with the IPv4 address space (Note &#8211; This is obviously not enough for granular 128bit IPv6 addressing). It is the easiest way to solve the start <= IP <= end of problem with IP-and floating numers is the following piece of code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">$ Lower_dec <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>float<span style="color: #009900;">&#41;</span> <span style="color: #990000;">sprintf</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;<span style="color: #009933; font-weight: bold;">% u</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">ip2long</span> <span style="color: #009900;">&#40;</span>$ lower<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        $ Upper_dec <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>float<span style="color: #009900;">&#41;</span> <span style="color: #990000;">sprintf</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;<span style="color: #009933; font-weight: bold;">% u</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">ip2long</span> <span style="color: #009900;">&#40;</span>$ top<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        $ Ip_dec <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>float<span style="color: #009900;">&#41;</span> <span style="color: #990000;">sprintf</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;<span style="color: #009933; font-weight: bold;">% u</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">ip2long</span> <span style="color: #009900;">&#40;</span>$ ip<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>$ ip_dec<span style="color: #339933;">&gt;</span> <span style="color: #339933;">=</span> $ lower_dec<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span> <span style="color: #339933;">&amp;</span> <span style="color: #009900;">&#40;</span>$ ip_dec <span style="color: #339933;">&lt;=</span> $ upper_dec<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Next we have the challenge of handing the CIDR netmasks. What we can do is to create a format CIDR IP address / netmask, and calculate the start and end IP addresses of this block and proceed as before &#8211; but that would not take a joke &#8211; and would mean that I do not really taught by this article.</p>
<p>The method we use here is how the whole world of Internet routers, if a destination IP is in a given CIDR address space. And we receive and dirty with bitmask and bitwise logical operators.</p>
<p>This is a real world example, my web server IP 80.76.201.37 and the netblock in which it resides, is 80.76.201.32/27, how does this all mean?</p>
<p>Well, the / 27 indicates that the first 27 bits of the IP address are the same network and IP address in this network (area) have the same only 27 bits are identical. Bits 28-32 are variable and may be 5 bits of the variation. If you know your binary, so this means, 32 IP addresses. (However, with routing, you can not use the top and bottom of a range of IP addresses, because this special and the network and broadcast addresses. [This is also the reason why a / 31 is not much (except for PPP connections) you can not use the 2-addresses, which gives you room]).</p>
<p>So thinking logically, bitwise, if my IP address and CIDR specification, then all I have to do is verify that the first 27 bits are all involved, and I&#8217;m good. Right. How would we do this in PHP? Sounds simple, can only use PHP&#8217;s bitwise logical AND operator: &#038;<br />
Also correct.</p>
<p>To achieve this, we need to convert 27 in 27, which really means &#8211; a 32-bit number of 27 ones and zeros in binary-5 (which is what really looks like 255,255,255,224).</p>
<p>In pseudo-code that you then do if (IP &#038; bitmask) == (RANGE &#038; bitmask), then everything is good and you know that the IP is in the area.</p>
<p>Visualization of this with our IP address (using the Unix tool very handy ipcalc):</p>
<p>      Address: 80.76.201.37 01010000.01001100.11001001.00100101<br />
      Netmask: 255,255,255,224 11111111.11111111.11111111.11100000<br />
      Wildcard: 0.0.0.31 00000000.00000000.00000000.00011111</p>
<p>      Network: 80.76.201.32/27 01010000.01001100.11001001.00100000<br />
      HostMin: 80.76.201.33 01010000.01001100.11001001.00100001<br />
      HostMax: 80.76.201.62 01010000.01001100.11001001.00111110<br />
      Broadcast: 80.76.201.63 01010000.01001100.11001001.00111111<br />
      Hosts / Net: 30</p>
<p>You can do this in the wild card line-0.0.0.31, and the network-ored with wildcard results in the broadcast address: 80.76.201.63.</p>
<p>Knowing this, then the IP address ANDed with the network address is the same value as the margin ANDed with the network address and thus can be used as a comparison for an IP Broadcast resident in this area.</p>
<p>How can we network address in PHP, we have two strategies, one is in such a simple substr () and take the left bits of the number pad and then just to the right with 0s. Or we can do some math with &#8220;NOT from 2 to the power of the (32-area) &#8211; 1&#8243;. In order for our value / 27 This gives us the decimal value 31, NOTED results (65536-31) (representation in bit-form &#8211; PHP, it is considered a negative whole number, but we do not need to worry about that).</p>
<p>I am sure that from now on, you scream for some code (and if you are stuck in this long, you really deserve it).</p>
<p>Code to manipulate a number / netmask in a broadcast address, with mathematics, provided:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">      $ Ip <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;80.76.201.37&quot;</span><span style="color: #339933;">;</span>
      $ Row <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;80.76.201.32&quot;</span><span style="color: #339933;">;</span>
      $ Netmask <span style="color: #339933;">=</span> <span style="color: #cc66cc;">27</span><span style="color: #339933;">;</span></pre></div></div>

<p>We can change the IP addresses too long integers with ip2long (with variable_dec &#8211; December is the abbreviation for decimal):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">      $ Range_dec <span style="color: #339933;">=</span> <span style="color: #990000;">ip2long</span> <span style="color: #009900;">&#40;</span>$ <span style="color: #990000;">range</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      $ Ip_dec <span style="color: #339933;">=</span> <span style="color: #990000;">ip2long</span> <span style="color: #009900;">&#40;</span>$ ip<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This gives us the basis of our mathematics, we need now only to the broadcast address.</p>
<p>Strategy 1 with str_pad to a string by padding with 0s and 1s.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">      $ Netmask_dec <span style="color: #339933;">=</span> <span style="color: #990000;">bindec</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">str_pad</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> $ netmask<span style="color: #339933;">,</span><span style="color: #0000ff;">'1 '</span><span style="color: #009900;">&#41;</span>
       <span style="color: #339933;">.</span> <span style="color: #990000;">str_pad</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">32</span> <span style="color: #339933;">-</span> $ netmask<span style="color: #339933;">,</span><span style="color: #0000ff;">'0 '</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>We can achieve the same result if the mathematics of NOTtin wildcard value. That is our strategy 2:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">      $ Wildcard_dec <span style="color: #339933;">=</span> <span style="color: #990000;">pow</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">32</span> <span style="color: #339933;">-</span> $ netmask<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
      $ Netmask_dec <span style="color: #339933;">=</span> ~ $ wildcard_dec<span style="color: #339933;">;</span></pre></div></div>

<p>Once we know that the netmask address (decimal), as we have here, we know that if Anding this with the original IP results to check against the margin ANDed with the netmask, the IP is in the area, defined by the range / mask.</p>
<p>This can be done simply with:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">      <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>$ ip_dec <span style="color: #339933;">&amp;</span> $ netmask_dec<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #009900;">&#40;</span>$ range_dec <span style="color: #339933;">&amp;</span> $ netmask_dec<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I moved all this logic in an easy to make the file to a single function ip_in_range ($ ip, $ range) in which $ ip is the IP address you want to validate and $ field is a one of the above formats , Wild Card, start-end solution or CIDR. The function is a simple TRUE or FALSE, if the IP is in this area.</p>
]]></content:encoded>
			<wfw:commentRss>http://ersinacar.com/determine-whether-an-ip-is-within-a-certain-range_112.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP crypto functions</title>
		<link>http://ersinacar.com/php-crypto-functions_39.html</link>
		<comments>http://ersinacar.com/php-crypto-functions_39.html#comments</comments>
		<pubDate>Tue, 07 Apr 2009 17:48:56 +0000</pubDate>
		<dc:creator>Ersin Acar</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[cryptography]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[md5]]></category>

		<guid isPermaLink="false">http://ersinacar.com/?p=39</guid>
		<description><![CDATA[There are three available cryptographic functions in PHP, these are md5(), sha1() and crc32(). All of the functions take a string and output a value that is encrypted and can’t be reversed to the original string. In fact the only way to get the original string back is to run a brute force algorithm which [...]]]></description>
			<content:encoded><![CDATA[<p>There are three available cryptographic functions in PHP, these are md5(), sha1() and crc32(). All of the functions take a string and output a value that is encrypted and can’t be reversed to the original string. In fact the only way to get the original string back is to run a brute force algorithm which tries to guess what the original string was.</p>
<p>To test these functions I will use the following string.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'wibble'</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>md5()</strong><br />
This function returns the hash as a 32-character hexadecimal number. The md5() function is used quite a bit and most PHP programmers will have come across it at some point.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//returns 50eccc6e2b0d307d5e8a40fb296f6171</span></pre></div></div>

<p>The md5() and sh1() functions have a second parameter which makes the function return binary data if set to true (the default is false). This returns binary data, which can be turned back into a hexadecimal number by using the bin2hex() function.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">bin2hex</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This function returns the same as in the previous example.<br />
<span id="more-39"></span><br />
<strong>sha1()</strong><br />
sha1() returns the sha1 hash as a string 40 characters long. This function is more secure than the md5() function as there is a lesser chance of guessing what the original string was.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">sha1</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//returns 02e0182ae38f90d11be647e337665e67f9243817</span></pre></div></div>

<p>The sha1() function can also be made to return binary data if the second optional parameter is set to true.</p>
<p><strong>crc32()</strong><br />
This isn’t really a cryptographic function, but it can be used in a similar way as a string will always come out with the same result. This function returns the crc32 polynomial of a string as an integer.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">crc32</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//returns 489363548</span></pre></div></div>

<p>Because of the way that PHP stores integers (as signed), quite a few of the results of this function will be negative. For example, the string &#8220;wibble&#8221; will return a positive integer, but the string &#8220;wobble&#8221; will return a negative number, which must be compensated for. This can be fixed by using the &#8220;%u&#8221; formatter of the sprintf() function, which will return a string containing the correct integer value.</p>
<p>This hashing function is intended to be used as part of a hash table and not as a mechanism of security. This is because it is very easy to generate a &#8220;hash collision&#8221; where two separate strings have the same hash value. I include this here to give you that warning.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #009933; font-weight: bold;">%u</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">crc32</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// returns 489363548</span></pre></div></div>

<p><strong>crypt()</strong><br />
The crypt() function will take a string as input and produce a variety of different outputs depending on the current system and environment. The salt is the second parameter and if you don’t include this the function will generate a salt for you, which causes the outcome of the hash to be different every time. An important thing to note is that the value of the salt value effects what hashing algorithm is used. There are a set of constants that can be used if you want to detect if an encryption algorithm is available.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> CRYPT_STD_DES <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #990000;">crypt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'st'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">// returns something like &quot;stNPuLMaoIxdU&quot;</span></pre></div></div>

<p>If you want to compare a password then you must pass the entire result of crypt() as the salt for a crypt of the password. For example, the following is incorrect.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$one</span> <span style="color: #339933;">=</span> <span style="color: #990000;">crypt</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'one'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$two</span> <span style="color: #339933;">=</span> <span style="color: #990000;">crypt</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'one'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$one</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$two</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// returns false</span></pre></div></div>

<p>Adding a salt to the second crypt() call gives us the correct answer.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$one</span> <span style="color: #339933;">=</span> <span style="color: #990000;">crypt</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'one'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$two</span> <span style="color: #339933;">=</span> <span style="color: #990000;">crypt</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'one'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$one</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$one</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$two</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// returns true</span></pre></div></div>

<p>As with all hashing functions there is no decrypt function as this is a one way process.</p>
<p><strong>hash()</strong><br />
The hash() function is a multi use function that takes two parameters as a default. The first is the hashing algorithm that will be used and the second is the string to be hashed. To encode the string using the whirlpool algorithm use the following code.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">hash</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;whirlpool&amp;quotl, <span style="color: #006699; font-weight: bold;">$string</span>);
// returns 91cefc6cc8eecf3a0ef18889bc3b06e7217ce7d41e1d0d5e37709415c3a98e450c53e62ae57680a011a08ef65429e6ba76701c703fcfc4c63938a4aa61737c38</span></pre></div></div>

<p>To find out what hashing algorithms your system supports you can use the hash_algos() function. This returns an array of the available algorithms.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">hash_algos</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>If you have haval256,5 available in this list then I suggest you use it as it produces the safest hash value. More information about the hash functions can be found in the <a href="http://www.php.net/manual/en/ref.hash.php">hash section of the PHP documentation.</a></p>
<p><strong>Breaking The Code</strong><br />
It isn’t possible to break a md5 of sha1 encoded string, but this can only be done by trying to guess the original value. The site <a href="http://md5.rednoize.com/">md5.rednoize.com</a> can break a string that you enter, but only because it contains 47 million hashes and can therefore reverse engineer the value of the hash.</p>
<p>To stop this happening to your passwords you can use what is called a salt value. Rather than directly encode the value of the password you store the password along with a salt, which is kept secret. An attacker needs to know the value of the salt value before they can correctly guess a users password.<br />
</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ersinacar.com/php-crypto-functions_39.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shortening a string in PHP</title>
		<link>http://ersinacar.com/shortening-a-string-in-php_31.html</link>
		<comments>http://ersinacar.com/shortening-a-string-in-php_31.html#comments</comments>
		<pubDate>Tue, 07 Apr 2009 15:13:37 +0000</pubDate>
		<dc:creator>Ersin Acar</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[shortening]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[substr]]></category>

		<guid isPermaLink="false">http://ersinacar.com/?p=31</guid>
		<description><![CDATA[1 2 3 4 5 6 7 8 9 10 11 function ShortText&#40;$text&#41; &#123; // display char lenght $chars = 10; $text = $text.&#34; &#34;; $text = substr&#40;$text,0,$chars&#41;; $text = substr&#40;$text,0,strrpos&#40;$text,' '&#41;&#41;; $text = $text.&#34;...&#34;; // You can give a link here return $text; &#125; //usage; echo ShortText&#40;&#34;it's a very very very very very very [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">function</span> ShortText<span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// display char lenght</span>
        <span style="color: #000088;">$chars</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$text</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$chars</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #990000;">strrpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span><span style="color: #0000ff;">' '</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$text</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;...&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// You can give a link here</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$text</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">//usage;</span>
<span style="color: #b1b100;">echo</span> ShortText<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;it's a very  very very very very very very longggggggggggggg text&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://ersinacar.com/shortening-a-string-in-php_31.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GD security image function</title>
		<link>http://ersinacar.com/gd-security-image-function_17.html</link>
		<comments>http://ersinacar.com/gd-security-image-function_17.html#comments</comments>
		<pubDate>Mon, 06 Apr 2009 06:57:50 +0000</pubDate>
		<dc:creator>Ersin Acar</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[font]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[gd]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://ersinacar.com/?p=17</guid>
		<description><![CDATA[Hi! i made this function at 2006 but still using it&#8217;s very usefull! image.php; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 &#60;?php function createimg &#40;&#41; &#123; session_start&#40;&#41;; ini_set&#40;&#34;session.gc_maxlifetime&#34;,&#34;36000&#34;&#41;; $fontnum=6; //count of fonts $numbers = strtoupper&#40;substr&#40;rand&#40;0,999999999999&#41;,-3&#41;&#41;; $_SESSION&#91;&#34;guv&#34;&#93; = $numbers; [...]]]></description>
			<content:encoded><![CDATA[<p>Hi!<br />
i made this function at 2006 but still using it&#8217;s very usefull!</p>
<p>image.php;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> createimg <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #990000;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;session.gc_maxlifetime&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;36000&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$fontnum</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">6</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//count of fonts</span>
	<span style="color: #000088;">$numbers</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtoupper</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">999999999999</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,-</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;guv&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$numbers</span><span style="color: #339933;">;</span> 
	<span style="color: #000088;">$im</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatetruecolor</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">125</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">75</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #000088;">$white</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecolorallocate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">imagefilledrectangle</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">400</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">200</span><span style="color: #339933;">,</span> <span style="color: #000088;">$white</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span>strlen<span style="color: #009900;">&#40;</span><span style="color: #000088;">$numbers</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$font</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;fonts/&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #000088;">$fontnum</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.TTF&quot;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">%</span><span style="color:#800080;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$angel</span><span style="color: #339933;">=</span><span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$angel</span><span style="color: #339933;">=</span><span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">330</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">360</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
			imagettfnumbers<span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">25</span><span style="color: #339933;">,</span> <span style="color: #000088;">$angel</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">+</span><span style="color: #000088;">$i</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">35</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">49</span><span style="color: #339933;">,</span> <span style="color: #990000;">imagecolorallocate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">250</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">250</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">250</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$font</span><span style="color: #339933;">,</span><span style="color: #000088;">$numbers</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$x</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span> <span style="color: #000088;">$y</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span> <span style="color: #000088;">$size</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">200</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-type: image/png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">imagepng</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
createimg<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>You need 6 fonts in ./fonts directory like;<br />
1.TTF<br />
2.TTF<br />
3.TTF<br />
4.TFF<br />
5.TFF<br />
6.TFF</p>
<p>usage example;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>img src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;imgcode.php&quot;</span> alt<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;security&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;guv&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;guv&quot;</span><span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;!--</span> and also i made a relod image button here it is<span style="color: #339933;">;</span> <span style="color: #339933;">--&gt;</span>
<span style="color: #339933;">&lt;</span>img src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;images/reload.gif&quot;</span> width<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;16&quot;</span> height<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;16&quot;</span> border<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;0&quot;</span> alt<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;refresh&quot;</span> onclick<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;i=i+1; document.getElementById('guv').src='imgcode.php?id='+i&quot;</span><span style="color: #339933;">/&gt;</span></pre></td></tr></table></div>

<p>Here is the a screen shot;<br />
<img src="http://ersinacar.com/wp-content/uploads/2009/04/secimg.jpg" alt="secimg" title="security image" width="146" height="70" class="alignnone size-full wp-image-18" /><br />
</br></br></br></p>
]]></content:encoded>
			<wfw:commentRss>http://ersinacar.com/gd-security-image-function_17.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

