User Tools

Site Tools

tools:php

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tools:php [2024/06/03 03:27] – [Types of variables] Humphrey Boa-Garttools:php [2025/10/12 10:53] (current) Humphrey Boa-Gart
Line 1: Line 1:
-{{wst>iw-import}} +#redirect tools:languages:php
- +
-====== PHP ====== +
- +
-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 [[tools:html|HTML]] is highly recommended. If you've programmed in another web language such as ASP, or have knowledge of application languages like [[tools:cplusplus|C++]] or Java, learning PHP will be considerably easier. +
- +
-===== 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, while, for, do-while, for-each loops, functions, or classes end in semicolons. +
-==== Hello World, Again (with HTML) ==== +
- +
-We saw how echo can output text. But it can also output HTML code and JavaScript. Example here. +
- +
-  <?php +
-    echo "<b>bold text</b> <i>italic text</i>"; +
-  ?> +
- +
-This'll output **bold text** //italic text//, 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 . " " .  $wut . " " .$randomdigit . " times?"; +
-  ?> +
- +
-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; +
-  ?> +
- +
-This sends out "Constant Value"+
-===== Predefined variables ===== +
- +
-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 +
- +
-(Depending on your server environment.) +
-==== 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 ==== +
- +
-==== Assignment ==== +
- +
-==== Logical ==== +
- +
-==== Comparison ==== +
- +
-==== Conditional statements and loops ==== +
- +
-==== Conditional statements ==== +
- +
-==== If ==== +
- +
-==== Switch ==== +
- +
-===== Loops ===== +
- +
-==== For loops ==== +
- +
-==== Foreach loops ==== +
- +
-==== While loops ==== +
- +
-==== Do-while loops ==== +
- +
-==== Simple Backdoor in PHP ==== +
- +
-==== Email flooder in PHP ==== +
- +
-===== Image bugs ===== +
- +
-{{tag>Tools Programming Stubs}}+
tools/php.1717385255.txt.gz · Last modified: (external edit)

Find this page online at: https://bestpoint.institute/tools/php