<?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>Thronic.com &#187; PHP</title>
	<atom:link href="http://thronic.com/category/development/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://thronic.com</link>
	<description>Personal Computing and Development by Dag J. Nedrelid</description>
	<lastBuildDate>Wed, 28 Apr 2010 12:21:44 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>String encryption in PHP</title>
		<link>http://thronic.com/2009/development/string-encryption-in-php/</link>
		<comments>http://thronic.com/2009/development/string-encryption-in-php/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 23:05:50 +0000</pubDate>
		<dc:creator>Dag Jonny Nedrelid</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WebDev]]></category>

		<guid isPermaLink="false">http://thronic.com/?p=150</guid>
		<description><![CDATA[I&#8217;ve been working on 2 PHP functions that can be used to encrypt and decrypt alphanumeric strings between web pages. This is used for e.g. Captcha codes that you can generate yourself and encrypt / decrypt with these functions.

How does it work?
A key is generated on the first page that also encrypts the string (or [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on 2 PHP functions that can be used to encrypt and decrypt alphanumeric strings between web pages. This is used for e.g. Captcha codes that you can generate yourself and encrypt / decrypt with these functions.</p>
<p><span id="more-150"></span></p>
<p><strong>How does it work?</strong><br />
A key is generated on the first page that also encrypts the string (or code if you want). The same key is used on the second page to decrypt it. Consider the functions below for more information. On the bottom you&#8217;ll find a test script to see the effect of the functions.<br />
<strong><br />
Generating a random string value in PHP (e.g a Captcha code):</strong></p>
<blockquote>
<pre><code>function CreateRandomStringPHP() {
  $code = substr(str_shuffle('abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789'),0,5);
  return $code;
}</code></pre>
</blockquote>
<p>If you are using another language, consider using a function like this:</p>
<blockquote>
<pre><code>function CreateRandomString() {
  $Characters = array(
  'a','b','c','d','e','f','g','h','i','j','k','m','n','p','q','r','s','t','u','v','w','x','y','z',
  'A','B','C','D','E','F','G','H','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y','Z',
  '2','3','4','5','6','7','8','9');

  $Code = '';
  for( $loop_b = 1; $loop_b &lt;= 5; $loop_b++ ) {
    $Code .= $Characters[mt_rand(0,count($Characters)-1)];
  }

  return $Code;
}</code></pre>
</blockquote>
<p>Both of the above functions will generate a 5-length value. This will provide one value out of 550731776 possible combinations which should be enough for most needs.</p>
<p><strong>The lock (or encrypt) function:</strong></p>
<blockquote>
<pre><code>/*
  str LockCode(str $code, str $key)

  A codelock function (or encryption if you want).
  I wrote because I wanted a nice solution for keeping codes
  such as Captcha codes safe and secure for transferring between
  sites.

  It takes a $code of random length and locking $key as parameters.
  You'll need to use the same key to unlock it.

  The value this function returns, is simply a set of location
  coordinates in the key where the characters of the $code is found.
  This is again merged together with the lengths of every coordinate,
  since every coordinate can be 1 or 2 in length as long as the $key
  is under 100 characters in length (0-99).

  In the end, it should provide a safely locked $code, based on that
  you keep the $key hidden. Do NOT show it in your HTML. The key
  used in this example, with 56 alphanumeric characters where I have
  stripped out the following chars: 1, I, l, o, O and 0 (they are
  unpractical) has 7,9164324866862966607842406018063e+97
  combinations. This should be enough to keep the $code safe...
*/
function LockCode($code,$key) {
  $key_chars = str_split($key);
  $code_chars = str_split($code);
  $LockedKeyCoords = '';
  $LockedCoordLengths = '';

  foreach($code_chars as $c_char) {
    for($loop_a=0; $loop_a&lt;count($key_chars); $loop_a++) {
      if($c_char==$key_chars[$loop_a]) {
        $LockedKeyCoords .= (string)$loop_a;
        $LockedCoordLengths .= (string)strlen($loop_a);
      }
    }
  }

  return $LockedKeyCoords . $LockedCoordLengths;
}</code></pre>
</blockquote>
<p><strong>The unlock (or decrypt) function:</strong></p>
<blockquote>
<pre><code>/*
  str UnlockCode(str $coords, str $key, int $keylength)

  The unlock function introduces a new parameter: $Keylength.
  This defines how many characters your $code was before you locked it.
*/
function UnlockCode($coords,$key,$keylength) {
  $key_chars = str_split($key);
  $keylengths = str_split(substr($coords,-$keylength));
  $UnlockedCode = '';

  foreach($keylengths as $length) {
    $UnlockedCode .= $key_chars[(int)substr($coords,0,(int)$length)];
    $coords = substr($coords,(int)$length);
  }

  return $UnlockedCode;
}</code></pre>
</blockquote>
<p>PHP code to test with:</p>
<blockquote>
<pre><code>/*
  The $Key MUST contain the characters you use to create the
  code with. Using the same string as you did to make the $Code
  with is a good choice. Generate a key on a standalone page,
  then use the same key on the page that locks the string, and
  on the page that unlocks the string.

  If you want a new random key every time you use the locking
  functions, you'll have to use a database system to store and
  retrieve them. And use sessions for identifying the keys. This
  would make a separate article, so I won't explain how to do it
  here.
*/
$Key = str_shuffle('abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789');

// Test it out.
$Code = CreateRandomStringPHP();
$LockedCode = LockCode($Code,$Key);
echo 'Key used: '. $Key .'&lt;br&gt;&lt;br&gt;';
echo 'New code: '. $Code .'&lt;br&gt;';
echo 'Locked code: '. $LockedCode .'&lt;br&gt;';
echo 'Unlocked code: '. UnlockCode($LockedCode,$Key,5) .'&lt;br&gt;&lt;br&gt;';
echo 'Reload this page to generate new results.';</code></pre>
</blockquote>
<p>The above testing code would produce something like this:</p>
<blockquote>
<pre><code>Key used: F7AYMQTscfHEPvSBXw5C3eWhj6kUxbn2ayrtGzNiqDV4m9ugJLKZpR8d

New code: c42yV
Locked code: 84331334212222
Unlocked code: c42yV</code></pre>
</blockquote>
<p>You can try it out yourself <a href="/pubfiles/string_encryption_example.php" target="_blank">here</a> (opens in a new window).</p>
]]></content:encoded>
			<wfw:commentRss>http://thronic.com/2009/development/string-encryption-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Alphanumeric Captcha values in PHP</title>
		<link>http://thronic.com/2009/development/alphanumeric-captcha-values-in-php/</link>
		<comments>http://thronic.com/2009/development/alphanumeric-captcha-values-in-php/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 13:47:31 +0000</pubDate>
		<dc:creator>Dag Jonny Nedrelid</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WebDev]]></category>

		<guid isPermaLink="false">http://thronic.com/?p=148</guid>
		<description><![CDATA[In my former post I wrote about making Captcha solutions without the need for database storage. I wrote an example exclusively based on pure numeric values. I&#8217;d like to illustrate how you could create alphanumeric Captcha values instead of numeric ones, as this might be of interest for someone who would like a more fully [...]]]></description>
			<content:encoded><![CDATA[<p>In my former post I wrote about making Captcha solutions without the need for database storage. I wrote an example exclusively based on pure numeric values. I&#8217;d like to illustrate how you could create alphanumeric Captcha values instead of numeric ones, as this might be of interest for someone who would like a more fully fledged solution.</p>
<p><span id="more-148"></span></p>
<p>In my last article, I used the following code to create a random numeric value:</p>
<blockquote><p>// 1000-9999 gives 5832 possibilies, strong enough for most captcha uses.<br />
$VerificationCode = rand(1000, 9999);</p></blockquote>
<p>You can use the following code instead to create a random alphanumeric value instead:</p>
<blockquote>
<pre><code>// This function will return a 5-length alphanumeric value.
// It will produce one out of 550731776 possible values.
function createCaptchaCode() {
  $stringChoices = array(
  'a','b','c','d','e','f','g','h','i','j','k','m','n','p','q','r','s','t','u','v','w','x','y','z',
  'A','B','C','D','E','F','G','H','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y','Z',
  '2','3','4','5','6','7','8','9');

  $code = '';
  for( $loop_b = 1; $loop_b &lt;= 5; $loop_b++ ) {
    $code .= $stringChoices[mt_rand(0,count($stringChoices)-1)];
  }
  return $code;
}</code></pre>
</blockquote>
<p>I suppose the above function could be written in PHP as simple as this:</p>
<blockquote><pre><code>function createCaptchaCode2() {
	$code = substr(str_shuffle('abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789'),0,5);
	return $code;
}</code></pre>
</blockquote>
<p>You might have noticed that the following characters are missing: 1, I, l, o, O and 0. This is to prevent unnecessary user frustration (they are very similar).</p>
<p>This covers how to generate a random alphanumeric value, what about encryption when you&#8217;re sending it between web pages? This subject is bigger than I thought it would be, so I&#8217;m going to make a new article on it. </p>
<p>You&#8217;ll find it <a href="http://thronic.com/articles/development/string-encryption-in-PHP/">here</a> when it&#8217;s ready.</p>
]]></content:encoded>
			<wfw:commentRss>http://thronic.com/2009/development/alphanumeric-captcha-values-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Your own numeric Captcha in PHP</title>
		<link>http://thronic.com/2009/development/your-own-numeric-captcha-in-php/</link>
		<comments>http://thronic.com/2009/development/your-own-numeric-captcha-in-php/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 17:06:13 +0000</pubDate>
		<dc:creator>Dag Jonny Nedrelid</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WebDev]]></category>

		<guid isPermaLink="false">http://thronic.com/?p=145</guid>
		<description><![CDATA[The purpose with a Captcha user control is to give the user a challenge that a computer normally can&#8217;t resolve. In most cases this means an image with random letters and numbers on it. This is rather easy to set up without any need for a database, that many use as a solution to handle [...]]]></description>
			<content:encoded><![CDATA[<p>The purpose with a Captcha user control is to give the user a challenge that a computer normally can&#8217;t resolve. In most cases this means an image with random letters and numbers on it. This is rather easy to set up without any need for a database, that many use as a solution to handle the encrypted messaging that has to happen between part1 and part2 in a Captcha utility.</p>
<p><span id="more-145"></span></p>
<p>The idea is to send the actual answer to the other side, but with a simple encryption.</p>
<blockquote><p>// First page variables.</p>
<p>// Create the random numeric code that a user/visitor will have to confirm it.<br />
// 1000-9999 gives 5832 possibilies, strong enough for most captcha uses.<br />
$VerificationCode = rand(1000, 9999);</p>
<p>// This is not a live example, so we&#8217;ll give $UserInput a manual value.<br />
// In your own script, you would capture what the user had typed in.<br />
$UserInput = &#8216;1234&#8242;;</p>
<p>// Create a key that only the other side will know.<br />
// Send this key together with the answer the user provided.<br />
$MySeed = 12345;<br />
$VerificationKey = ($VerificationCode + ($MySeed*(int)date(&#8216;d&#8217;)));</p>
<p>/*<br />
The key is now made based on your custom value ($MySeed) that only YOU will know. To hack the key, the hacker would have to know it. AND would have to know what you do with it. In this example we keep it dynamic from day to day by multiplying it with the current day extracted from the current date. It&#8217;s easy to figure out something else that would be much harder to guess.</p>
<p>Now you send both $UserInput and $VerificationKey to the next page.<br />
*/
</p></blockquote>
<blockquote><p>// Second page variables and handling.</p>
<p>// This naturally has to match the value in page one.<br />
$MySeed = 12345;</p>
<p>// Decrypt the key<br />
$ReceivedKey = ((int)$VerificationKey &#8211; ($MySeed*(int)date(&#8216;d&#8217;)));</p>
<p>// Now you can compare the user input with $ReceivedKey<br />
$VerificationStatus = ((int)$UserInput==$ReceivedKey?true:false);</p>
<p>echo ($VerificationStatus?&#8217;Accepted&#8217;:'Not accepted&#8217;);</p></blockquote>
<p><strong>Representing the random code to the user</strong><br />
When you have created a random number and/or code you can represent it to your visitor like this: <img src="/pubfiles/Verif/verif.php?c=1234" alt="" />. Images are widely used to ask Captcha questions since they are binary with different random colors and shapes that&#8217;s hard to scan for a bot that&#8217;s scanning the Internet to collect or spam information.</p>
<p><strong>Can I use your image script to show my random codes?</strong><br />
The image script I&#8217;ve used above takes a GET variable and prints it on a chosen image. It&#8217;s of no good use to anyone else other than an example, as it would be simple to just read the code right out of your source code for a spam-bot. So please make your own <img src='http://thronic.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Download your own copy WITH deciphering!</strong><br />
To make it easy for you, you can download the image script <a href="/pubfiles/Verif/verif.zip">here</a> and adapt it to your own needs. <em>(This image script is adjusted to receive a key and view it dechiphered, adjust after your own needs. Bots will NOT be able to scan the code from THIS script, unless they know your way of encrypting the key).</em></p>
]]></content:encoded>
			<wfw:commentRss>http://thronic.com/2009/development/your-own-numeric-captcha-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Recursive file searching function in PHP</title>
		<link>http://thronic.com/2009/development/recursive-file-searching-function-in-php/</link>
		<comments>http://thronic.com/2009/development/recursive-file-searching-function-in-php/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 10:02:27 +0000</pubDate>
		<dc:creator>Dag Jonny Nedrelid</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://thronic.com/?p=127</guid>
		<description><![CDATA[I recently made a search function for an image gallery that had to have the capability of searching for images in a directory and its subdirectories &#8211; on any level.  This is the second time ever that I have used a recursive function, this is a good example for when a recursive function can be [...]]]></description>
			<content:encoded><![CDATA[<p>I recently made a search function for an image gallery that had to have the capability of searching for images in a directory and its subdirectories &#8211; on any level.  This is the second time ever that I have used a recursive function, this is a good example for when a recursive function can be useful.</p>
<p><span id="more-127"></span></p>
<p><strong>What is a recursive function?</strong><br />
A recursive function is basically just a function that calls itself from within, making several instances of itself until you force it to stop. It&#8217;s good for when you don&#8217;t have a definitive concept depth to deal with, like searching for files through subdirectories, but don&#8217;t know how many directories and files there may be.</p>
<p>Here&#8217;s a recursive function I&#8217;ve made to search for images. It takes a search word and the folder to search in as first and second parameters.</p>
<blockquote>
<pre><code>// Recursive search function, a bit scary... I hope it won't make the universe implode on itself
function searchEngine($keyword, $folder) {
	global $SearchedImagesFoundCount, $SearchedImages;

	if($handle = opendir($folder)) {
		while(($file = readdir($handle)) !== false) {
			if((stristr($file,'.jpg') !== false || stristr($file,'.gif') !== false || stristr($file,'.png') !== false) &amp;&amp; stristr($file,$keyword) !== false) {
				$SearchedImagesFoundCount += 1;
				array_push($SearchedImages,$folder.'/'.$file);
			} elseif(is_dir($folder.'/'.$file) &amp;&amp; $file != '.' &amp;&amp; $file != '..') {
				// Ran into a folder, we have to dig deeper now
				searchEngine($keyword,$folder.'/'.$file);
			}
		}
		closedir($handle);
	}
}
</code></pre>
</blockquote>
<p>This is a stripped down version that might be easier to understand. This would simply search for a file (first parameter) in the given directory (second parameter).</p>
<blockquote>
<pre><code>function searchEngine($keyword, $folder) {
	if($handle = opendir($folder)) {
		while(($file = readdir($handle)) !== false) {
			if(stristr($file,$keyword) !== false) {
				// Action when a filename matching $keyword is found.
			} elseif(is_dir($folder.'/'.$file) &amp;&amp; $file != '.' &amp;&amp; $file != '..') {
				// Ran into a folder, we have to dig deeper now
				searchEngine($keyword,$folder.'/'.$file);
			}
		}
		closedir($handle);
	}
}
</code></pre>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://thronic.com/2009/development/recursive-file-searching-function-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>View your public IP address</title>
		<link>http://thronic.com/2009/computing/view-your-public-ip-address/</link>
		<comments>http://thronic.com/2009/computing/view-your-public-ip-address/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 22:34:46 +0000</pubDate>
		<dc:creator>Dag Jonny Nedrelid</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://thronic.com/?p=122</guid>
		<description><![CDATA[A small helpful script for viewing your public IP address. It will try to determine your real IP address even if you are hiding behind a proxy server.
You can find it here.

Code used to detect ip and proxy (PHP):

if ($_SERVER["HTTP_X_FORWARDED_FOR"]) {
  if ($_SERVER["HTTP_CLIENT_IP"]) {
    $proxy = $_SERVER["HTTP_CLIENT_IP"];
  } else {
 [...]]]></description>
			<content:encoded><![CDATA[<p>A small helpful script for viewing your public IP address. It will try to determine your real IP address even if you are hiding behind a proxy server.</p>
<p>You can find it <a href="/pubfiles/myip.php" target="_blank">here</a>.</p>
<p><span id="more-122"></span></p>
<p>Code used to detect ip and proxy (PHP):</p>
<blockquote>
<pre><code>if ($_SERVER["HTTP_X_FORWARDED_FOR"]) {
  if ($_SERVER["HTTP_CLIENT_IP"]) {
    $proxy = $_SERVER["HTTP_CLIENT_IP"];
  } else {
    $proxy = $_SERVER["REMOTE_ADDR"];
  }
  $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
} else {
  if ($_SERVER["HTTP_CLIENT_IP"]) {
    $ip = $_SERVER["HTTP_CLIENT_IP"];
  } else {
    $ip = $_SERVER["REMOTE_ADDR"];
  }
}</code></pre>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://thronic.com/2009/computing/view-your-public-ip-address/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick reference: PHP sessions</title>
		<link>http://thronic.com/2009/development/php/quick-reference-php-sessions/</link>
		<comments>http://thronic.com/2009/development/php/quick-reference-php-sessions/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 12:19:49 +0000</pubDate>
		<dc:creator>Dag Jonny Nedrelid</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://thronic.com/?p=164</guid>
		<description><![CDATA[Just a quick reference to what&#8217;s mainly needed to initiate and properly close a PHP session. I should have written this down a long time ago, since I often go back to php.net to look it up again.

Starting, and continuing a session
On every PHP page you want to take use of sessions, start the script [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick reference to what&#8217;s mainly needed to initiate and properly close a PHP session. I should have written this down a long time ago, since I often go back to php.net to look it up again.</p>
<p><span id="more-164"></span></p>
<p><strong>Starting, and continuing a session</strong><br />
On every PHP page you want to take use of sessions, start the script by calling <a href="http://no2.php.net/manual/en/function.session-start.php" target="_blank" title="Click for more information about this function from php.net">session_start()</a>.</p>
<p><strong>Registering session data</strong><br />
This is done by using the global $_SESSION array. Like this: $_SESSION['MyAge'] = &#8216;26&#8242;;</p>
<p><strong>Closing and terminating all session data</strong></p>
<blockquote><pre><code>$_SESSION = array();
if (isset($_COOKIE[session_name()])) {
  setcookie(session_name(), '', time()-42000, '/');
}
session_destroy();</code></pre>
</blockquote>
<p><strong>Additional info</strong><br />
All session data is stored server-side, with only a cookie on the client-side telling the server what session-id it should work with. If the client browser has high security and you are afraid that cookies might not be available, then you can add the constant SID to every hyperlink necessary in order to pass the session-id around. This constant will not have any value unless the cookie creation fails. </p>
<p><strong>A simple SID usage example</strong></p>
<blockquote><p><code>&lt;a href="index.php?&lt;?=SID?>">A link during a session that needs to have the session-id on the next page.&lt;/a></code></p></blockquote>
<p>If SID has a value, it would contain both the needed GET variable, and the session-id value. E.g. PHPSESSID=somevalue.</p>
<p><em>Get more information about php sessions over at <a href="http://www.php.net" target="_blank">php.net</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://thronic.com/2009/development/php/quick-reference-php-sessions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Base64 encoded PHP files</title>
		<link>http://thronic.com/2008/development/base64-encoded-php-files/</link>
		<comments>http://thronic.com/2008/development/base64-encoded-php-files/#comments</comments>
		<pubDate>Mon, 08 Sep 2008 10:16:23 +0000</pubDate>
		<dc:creator>Dag Jonny Nedrelid</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://thronic.com/?p=71</guid>
		<description><![CDATA[Some PHP files that comes along with script packages may often be encoded with base64. This is not a secure way of hiding code. Read further on this page if you want to know how to decode these kind of files.

Several of the files I&#8217;ve ran into have the same form of base64 encoding technique. [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Some PHP files that comes along with script packages may often be encoded with base64. This is not a secure way of hiding code. Read further on this page if you want to know how to decode these kind of files.</strong></p>
<p><span id="more-71"></span></p>
<p>Several of the files I&#8217;ve ran into have the same form of base64 encoding technique. This technique consists of 2 encoded parts. One part that holds the main code, and another part that decodes the first part and swaps around a few characters to make it valid.</p>
<p>The common contents of an encoded base64 file from a publisher could look like this (usually in 1 unbroken string but I split it up here to make it more readable):</p>
<blockquote><p><code> $_F=__FILE__;<br />
$_X='encoded_part1';<br />
$_D=strrev('edoced_46esab');<br />
eval($_D('encoded_part2'));<br />
?&gt;<br />
</code></p></blockquote>
<p>Where the encoded part2 usually contain something like this:</p>
<blockquote><p><code>$_X=base64_decode($_X);<br />
$_X=strtr($_X,'something','something');<br />
$_R=ereg_replace('__FILE__',"'".$_F."'",$_X);<br />
eval($_R);<br />
</code></p></blockquote>
<p><strong>Solution</strong><br />
So all you need to do to view the real contents of any base64 encoded file that uses this method is just replacing the &#8220;eval&#8221; in encoded part2 with e.g. &#8220;echo&#8221; to view the final decoded code instead of running it.</p>
<p>To get to the contents of encoded part1, you just replace &#8220;eval&#8221; with &#8220;echo&#8221; there as well, which is never encoded to begin with.</p>
<p><strong>Additional notes</strong><br />
Remember to view the source instead of just trusting screen output if viewing through a browser when analyzing output results.</p>
<p>As an additional comment, this way of hiding the source code is a quick and dirty and not secure way at all of doing it, and I was surprised to encounter it. If someone wants your code, they are most likely very fit to do this process to get it. Even if you have several hundred files, a script could be made to decode all of them in 1 batch.</p>
<p>A reason for wanting to decode some of these files, is often to see if the script is malicious or honest in its purpose.</p>
]]></content:encoded>
			<wfw:commentRss>http://thronic.com/2008/development/base64-encoded-php-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple HTML 2 PDF using PHP</title>
		<link>http://thronic.com/2008/development/simple-html-2-pdf-using-php/</link>
		<comments>http://thronic.com/2008/development/simple-html-2-pdf-using-php/#comments</comments>
		<pubDate>Thu, 12 Jun 2008 10:32:48 +0000</pubDate>
		<dc:creator>Dag Jonny Nedrelid</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WebDev]]></category>

		<guid isPermaLink="false">http://thronic.com/?p=74</guid>
		<description><![CDATA[The following is a nice alternative for those who need to generate dynamic PDF documents on-the-go. This class does not require any PDF extensions to be loaded in the PHP configuration.

The class is simple to load and use right away. You can find the class and it&#8217;s documentation on it&#8217;s website here: http://html2fpdf.sourceforge.net/
It is based [...]]]></description>
			<content:encoded><![CDATA[<p><strong>The following is a nice alternative for those who need to generate dynamic PDF documents on-the-go. This class does not require any PDF extensions to be loaded in the PHP configuration.</strong></p>
<p><span id="more-74"></span></p>
<p>The class is simple to load and use right away. You can find the class and it&#8217;s documentation on it&#8217;s website here: <a href="http://html2fpdf.sourceforge.net/" target="_blank">http://html2fpdf.sourceforge.net/</a></p>
<p>It is based upon (F)PDF which you can find here: <a href="http://www.fpdf.org/" target="_blank">http://www.fpdf.org/</a></p>
<p>You can download a usable version directly from <a href="/pubfiles/html2fpdf-3.0.2b.zip">here</a></p>
<p>The purpose of this class is to make the creation of PDF documents from HTML formatting easier, and it does the job fairly well. It seems to understand many of the most important HTML elements, as well as some CSS.</p>
<p>An example of simple usage:</p>
<blockquote>
<pre><code>&lt;?php
// ---------------------------------
// HTML 2 (F)PDF

// Homepage for this class:
// http://html2fpdf.sourceforge.net/

// Homepage for the class which it is based on:
// http://www.fpdf.org/
// ---------------------------------
require_once('html2fpdf.php');
ob_start();
?&gt;

&lt;html&gt;
&lt;body&gt;
&lt;h1&gt;My PDF test&lt;/h1&gt;
&lt;div align="center"&gt;Hello, World!&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;

&lt;?php
$html = ob_get_contents();
ob_end_clean();
$pdf = new HTML2FPDF();
$pdf-&gt;SetTopMargin(1);
$pdf-&gt;AddPage();
$pdf-&gt;WriteHTML($html);
$pdf-&gt;Output('test.pdf','D');
?&gt;</code></pre>
</blockquote>
<p><a href="/pubfiles/html2pdf_example.pdf" target="_blank">View example</a></p>
]]></content:encoded>
			<wfw:commentRss>http://thronic.com/2008/development/simple-html-2-pdf-using-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP excel export without saving a file</title>
		<link>http://thronic.com/2008/development/php-excel-export-without-saving-a-file/</link>
		<comments>http://thronic.com/2008/development/php-excel-export-without-saving-a-file/#comments</comments>
		<pubDate>Mon, 07 Apr 2008 11:07:46 +0000</pubDate>
		<dc:creator>Dag Jonny Nedrelid</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WebDev]]></category>

		<guid isPermaLink="false">http://thronic.com/?p=78</guid>
		<description><![CDATA[A simple way of exporting data to the web in excel format, you don&#8217;t have to create an excel file, you just have to define the proper headers for the browser.

-
First define a filename, and headers.
$filename = "test.xls";
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Type: application/vnd.ms-excel");
Now just send the clear text data you want the excel file to contain, use [...]]]></description>
			<content:encoded><![CDATA[<p style="font-weight: bold;">A simple way of exporting data to the web in excel format, you don&#8217;t have to create an excel file, you just have to define the proper headers for the browser.</p>
<p><span id="more-78"></span><br />
<span style="color: #ffffff;">-</span></p>
<p style="font-weight: bold;">First define a filename, and headers.</p>
<blockquote><p><code>$filename = "test.xls";<br />
header("Content-Disposition: attachment; filename=\"$filename\"");<br />
header("Content-Type: application/vnd.ms-excel");</code></p></blockquote>
<p>Now just send the clear text data you want the excel file to contain, use &#8220;\n&#8221; and &#8220;\t&#8221; for row and column navigation.</p>
<p style="font-weight: bold;">For example:</p>
<blockquote><p><code>echo "column1 \t column2\n";<br />
echo "row1 value1" . "\t" . "row1 value2\n";<br />
echo "row2 value1" . "\t" . "row2 value2";<br />
exit(); //remember to stop output unless you do it its own file.</code></p></blockquote>
<p>Click the excel icon below to see how the export of this data would look like.</p>
<p><a title="Click to download direct XLS sample" href="/pubfiles/export_excel_example.php"><img src="http://thronic.com/wp-content/uploads/2009/06/excel_icon.gif" border="0" alt="ExcelIcon" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://thronic.com/2008/development/php-excel-export-without-saving-a-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP SimpleXML</title>
		<link>http://thronic.com/2008/development/php-simplexml/</link>
		<comments>http://thronic.com/2008/development/php-simplexml/#comments</comments>
		<pubDate>Mon, 24 Mar 2008 11:40:25 +0000</pubDate>
		<dc:creator>Dag Jonny Nedrelid</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://thronic.com/?p=82</guid>
		<description><![CDATA[A quick article on PHP&#8217;s SimpleXML.
SimpleXML provides a simple and practical way of reading and handling XML content. SimpleXML requires PHP5.

First you define your XML document source
$xml = new SimpleXMLElement(file_get_contents('http://example.com/rss/'));
Then you choose what structure to get from the XML, in this example I want to loop through all the &#60;item&#62; tags under the first &#60;channel&#62;. [...]]]></description>
			<content:encoded><![CDATA[<p><strong>A quick article on PHP&#8217;s SimpleXML.</strong></p>
<p>SimpleXML provides a simple and practical way of reading and handling XML content. SimpleXML requires PHP5.</p>
<p><span id="more-82"></span></p>
<p>First you define your XML document source</p>
<blockquote><p><code>$xml = new SimpleXMLElement(file_get_contents('http://example.com/rss/'));</code></p></blockquote>
<p>Then you choose what structure to get from the XML, in this example I want to loop through all the &lt;item&gt; tags under the first &lt;channel&gt;. Then I want to view the &lt;title&gt; of each item, as well as a download count from the &#8216;download&#8217; namespace. The XML could look something like this:</p>
<p style="color: blue;">&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;UTF-8&#8243; ?&gt;<br />
&lt;rss xmlns:download=&#8221;http://example.com/rss/downloadModule#&#8221; version=&#8221;2.0&#8243;&gt;</p>
<p style="color: blue;">&lt;channel&gt;<br />
<span style="padding-left:10px">&lt;item&gt;</span><br />
<span style="padding-left:20px">&lt;title&gt;The Title&lt;/title&gt;</span><br />
<span style="padding-left:20px">&lt;download:count&gt;12345&lt;/download:count&gt;</span><br />
<span style="padding-left:10px">&lt;/item&gt;</span><br />
<span style="padding-left:10px">&lt;item&gt;</span><br />
<span style="padding-left:20px">&lt;title&gt;The Title 2&lt;/title&gt;</span><br />
<span style="padding-left:20px">&lt;download:count&gt;1234&lt;/download:count&gt;</span><br />
<span style="padding-left:10px">&lt;/item&gt;</span><br />
&lt;/channel&gt;</p>
<p>SimpleXML works through arrays. Here I&#8217;m telling it to loop through the first &lt;channel&gt; by writing &#8216;channel[0]&#8216;, and then the item collection within that channel. This small example illustrates how to handle both normal tags and namespaces.</p>
<blockquote><p><code>foreach( $xml-&gt;channel[0]-&gt;item as $item ) {<br />
// The download namespace<br />
$download = $item-&gt;children('http://example.com/rss/downloadModule#');</code></p>
<p><code>// View item title<br />
echo $item-&gt;title;</code></p>
<p><code>// The download count<br />
echo $downloads-&gt;count;<br />
}</code></p></blockquote>
<p>I haven&#8217;t had any need for it yet, but to get the attributes within a tag you should only have to do something like this:</p>
<blockquote><p><code>$attributes = $item-&gt;attributes();</code></p>
<p><code>// View attributes through names:<br />
echo $attributes-&gt;attribute1;<br />
echo $attributes-&gt;attribute2;</code></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://thronic.com/2008/development/php-simplexml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
