First part of the explanation stuff:
I've seperated out the code to be more readable.
I have also returned the variables to their less cryptic names.
$theNum is now $number_of_pictures. The cookie 'cookie' is now 'mwarotate'.
header("location: ./".(
( ($number = (
($number_of_pictures = 7) &&
($temp = ( isset( $_COOKIE['mwarotate'] ) )?( $_COOKIE['mwarotate']+1):1) &&
($temp == $number_of_pictures)
)?0:$temp ) &&
( setcookie("mwarotate", $number, time()+60*60*24*365, "/") || 1 )
)?(
($number==0)? $number_of_pictures - 1 : $number - 1
) : "error" )
.".png")
It also just so happens that I've split the code up into blocks that I'm going to address one at a time.
But first, a bit of general knowlage that you need to know to understand this.
One;
Variables are text with the dollar sign in front of them. ($).
This means that it contains a value, that can be changed, using the =
operator.
$variable = "Value";
$foo = "bar";
Code between brackets, ()s, is executed as it's reached, but the rest of the code pauses, and the brackets turn into a literal constant. (A value.)
Logic, true or false, is represented by the numbers 1 and 0, representing true and false respectively. In fact, anything except 0 and NULL evaluates to true.
The operator '==' seems rather strange at first, but it means 'If this and this is equal'. It evaluates as true if it is, and false if not.
'=' is an
assignment operator. It evaluates to true if the assignment is successful.
This code uses the Ternary operator a lot. The syntax is "(
expression to test)?
value to return if expression is true:value to return if expression is false".
You can use this for assignment:
$foo = ( $Mwa == "1337" )?"bar":"wtf";
You can also use it in the middle of another expression.
$foo = ( $Mwa == "1337" )?((xhtml > HTML)?"bar":"flawed"):"wtf";
Onwards!
header("location: ./".(
The first line indicates that we are going to use the header(); function, which allows you to set the outgoing headers.
If you don't understand this, don't worry, all you need to know is that header( "Location:
URL" ); will redirect the user to another page.
We speficy './' meaning in the current driectory, then close the speachmarks. We place a period, '.' to signify that this isn't the end of the string, and there is more to come.
Then we open the brackets that enclose the giant ternary operator that sets the URL that the user is redirected to.