News Archive
PhpRiot Newsletter
Your Email Address:

More information

PHP nonalpha tutorial

Note: This article was originally published at Planet PHP on 19 April 6840.
Planet PHP

My first post on PHP non-alpha numeric code was a bit brief, in the excitement of the discovery I failed to detail in depth the process. I've decided to follow up with a tutorial and hopefully explain the process better for anyone wanting to learn or improve the technique.

The basis of PHP non-alphanumeric code is to take advantage of the fact that PHP automatically converts Arrays into a string aoArraya when using in a string context. A simple example would be:

$x = array(1,2,3);
echo $x;//output Array

$x is now the string aoArraya. But you will notice we used alphanumeric characters, we can also create an array without using array() like the following:

echo $_;//output Array

The first part creates a variable ao$_a the second part references 0 by using the infix operator on a blank string to convert to 0, the assignment creates the array. This was a first attempt to hack together an array when I first wrote it but all sorts of tricks can be used for example you don't need the ao0a part.

echo $_;//output Array

I'll leave you to experiment for ways to create arrays but you get the idea. Right we have the characters aoAa, aora, aora and so on now we need to access them and fortunately PHP is very similar to JavaScript in that respect. The first step is to force our array into an actual string by concatenating it with a blank string like so:

$_=$_."";//$_ contains our array previously and forces it into a string

The next step is to actually access a letter and PHP conveniently provides the same accessor method as JavaScript. To do that we need zero, as I showed before using the infix operator with a blank string can convert to zero (also like JavaScript).

echo +"";// output 0

Using the 0 we can now access our letter aoAa from the converted array.

echo $_[+""]// output "A"

Now originally because I was just discovering the technique I did some crazy math operations on multiple characters to obtain other characters than Array but this wasn't necessary as Stefan Esser pointed out you can simply increment/decrement strings. But anyway I figured the letters out by doing nested for loops of all the characters, I'll post the script if I've still got it later. For now though we'll simply increment/decrement the characters we need. I'll show you how to get the letter aoBa first.

$_="";//we need a blank string to start
$_[+$_]++;//access part of the string to convert to an array
$_=$_."";//convert the array into a string of "Array"
$_=$_[+""];//access the 0 index of the string "Array" which is "A"
echo ++$_;//increment "A" to "B"

That is the basis of how it works, we just need to construct a string that calls a function such as aochra or generate characters manually and then an eval based function to call our code. The original post used GET but since that is already documented I'll show you how to generate different code. We'll use the PHP function aoasserta since it evaluates code and it is allowed to be called using string references of it's name. For example:

$_("print 1+1;")//output 2

We therefore need to generate aoasserta and our code to call. Using the template from before were we generated aoArraya we simply create new references and increment the characters we need.

$_="";//we need a blank string to start
$_[+$_]++;//access part of the string to convert to an array
$_=$_."";//convert the array into a string of "Array"
$__=+"";//make zero
$__++;//increment to 1
$___=$_[+""];//access the 0 index of the string "Array" which is "A"
$____=$____=$_[$__];//access the 1 index of the string "Array" which is "r"
$_____=$____;// assign "r" to a new variable
$_____++;//increment to "s"
$______=$___;//new variable for "e"
$______++;$______++;$______++;$______++;//increment to "e"
$_=$___.$_____.$_____.$______.$____.++$_____;//concat the strings to form "AssErt"
$_("p".$____."in".$_____." $__+$__");//call print 1+1

You will notice there are missing characters at the end aopa, aoia and aona are alpha those are for you to generate using the techniques described. There are separate challenges to do after that for example a question to ask yourself is aoHow many characters are the minimum required to generate non-alphanumeric code?R

Truncated by Planet PHP, read more at the original (another 637 bytes)