Post by devguy on Aug 29, 2015 15:50:17 GMT -5
Example 1 - Show my IP
That will output your IP.
Exmaple 2 - Mathematical Calculations
Example 3 - $_GET examples
That code will output Hello World on screen if you add ?say=HelloWorld on the URL.
Example 4 - Loops
Example 5 - Cookies (set cookie and read cookie)
Example 5 - Variables
Example 6 - Comments
<?php
$ip = $_SERVER['REMOTE_ADDR'];
echo "Your IP is: $ip";
?>
That will output your IP.
Exmaple 2 - Mathematical Calculations
<?php
//Plus
$a = 2;
$b = 3;
$c = $a + $b;
echo $c;
//Minus
$aa = 2;
$bb = 3;
$cc = $aa - $bb;
echo $cc;
?>
Example 3 - $_GET examples
<?php
if($_GET['say'] == "HelloWorld") {
echo "HelloWorld";
}
?>
That code will output Hello World on screen if you add ?say=HelloWorld on the URL.
Example 4 - Loops
<?php
$x = 4;
while($x < 4)
{
echo $x;
$x--;
}
?>
Example 5 - Cookies (set cookie and read cookie)
<?php
$cookie = setcookie("Cookie Name", "Cookie Content");
if($_COOKIE['Cookie Name'] == "Cookie Content") {
echo $_COOKIE['Cookie Name'];
}
?>
Example 5 - Variables
<?php
$a = "This is a string"; //String
$b = 1; //Integer
$c = true; //Bool
?>
Example 6 - Comments
<?php
//One line comment
/*
More line comment
...
*/
?>