add this to git finally
This commit is contained in:
167
tutorial.php
Normal file
167
tutorial.php
Normal file
@ -0,0 +1,167 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Vulnerability testing</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Welcome to vulnerability testing! Powered by PHP!</h1>
|
||||
<?= 'Hello world!' ?>
|
||||
<?php
|
||||
// datatypes are inferred at runtime
|
||||
$name = "John";
|
||||
$age = 30;
|
||||
$height = 1.85;
|
||||
$isActive = true;
|
||||
$skills = ["PHP", "JS"];
|
||||
$person = null;
|
||||
|
||||
echo nl2br("\n\n");
|
||||
var_dump($skills);
|
||||
?>
|
||||
|
||||
<?php
|
||||
// type juggling
|
||||
$a = "5";
|
||||
$b = 2;
|
||||
|
||||
$c = $a+$b;
|
||||
|
||||
echo nl2br("\n\ntype juggling:\n");
|
||||
var_dump($c); // whaddaya think? of course, it's int(7)
|
||||
?>
|
||||
|
||||
<?php
|
||||
if ($age > 18) {
|
||||
echo "Adult";
|
||||
} elseif ($age > 12) {
|
||||
echo "Teenager";
|
||||
} else {
|
||||
echo "Child";
|
||||
}
|
||||
echo nl2br("\n\n");
|
||||
|
||||
switch($day) {
|
||||
case "Monday":
|
||||
echo "Start of week";
|
||||
break;
|
||||
case "Friday":
|
||||
echo "End of week";
|
||||
break;
|
||||
default:
|
||||
echo "Mid-week";
|
||||
}
|
||||
echo nl2br("\n\n");
|
||||
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
echo $i;
|
||||
}
|
||||
echo nl2br("\n\n");
|
||||
|
||||
$fruits = ["apple", "banana", "orange"];
|
||||
|
||||
foreach($fruits as $fruit) {
|
||||
echo $fruit;
|
||||
}
|
||||
echo nl2br("\n\n");
|
||||
|
||||
foreach($fruits as $index => $fruit) {
|
||||
echo "$index: $fruit";
|
||||
}
|
||||
echo nl2br("\n\n");
|
||||
|
||||
$i = 0;
|
||||
while ($i < 5) {
|
||||
echo $i++;
|
||||
}
|
||||
echo nl2br("\n\n");
|
||||
?>
|
||||
|
||||
<?php
|
||||
$name = "John";
|
||||
$age = 20;
|
||||
|
||||
echo "Hello, $name! You are $age years old!";
|
||||
|
||||
// for complex, use squirly braces {}
|
||||
/* echo "Hello, {$name}! In 5 years, you'll be {$age + 5} years old."; */ // HACK: doesn't work for some way?
|
||||
|
||||
// NOTE: single quote strings don't interpolate!!!
|
||||
echo nl2br("\n\n");
|
||||
?>
|
||||
|
||||
<?php
|
||||
function greet($name, $greeting = "Hello") {
|
||||
return "$greeting, $name!";
|
||||
}
|
||||
|
||||
echo greet("John");
|
||||
echo greet("Mary", "Hi");
|
||||
|
||||
$multiply = function($a, $b) {
|
||||
return $a * $b;
|
||||
};
|
||||
|
||||
echo $multiply(3,4);
|
||||
echo nl2br("\n\n");
|
||||
?>
|
||||
|
||||
<?php
|
||||
class Person {
|
||||
public $name;
|
||||
private $age;
|
||||
|
||||
public function __construct($name, $age) {
|
||||
$this->name = $name;
|
||||
$this->age = $age;
|
||||
}
|
||||
|
||||
public function greet() {
|
||||
return "Hello, my name is {$this->name} and I'm {$this->age} years old.";
|
||||
}
|
||||
|
||||
public function getAge() {
|
||||
return $this->age;
|
||||
}
|
||||
}
|
||||
|
||||
$person = new Person("John", 30);
|
||||
echo $person->greet();
|
||||
echo $person->getAge();
|
||||
echo nl2br("\n\n");
|
||||
?>
|
||||
|
||||
<?php
|
||||
$fruits = ["apple", "banana", "orange"];
|
||||
echo $fruits[0];
|
||||
echo nl2br("\n");
|
||||
|
||||
$person = [
|
||||
"name" => "John",
|
||||
"age" => 30,
|
||||
"city" => "NewYork"
|
||||
];
|
||||
echo $person["name"];
|
||||
echo nl2br("\n");
|
||||
|
||||
$users = [
|
||||
["name" => "John", "age" => 30],
|
||||
["name" => "Mary", "age" => 25],
|
||||
];
|
||||
echo $users[1]["name"];
|
||||
echo nl2br("\n");
|
||||
|
||||
$fruits[] = "grape"; // add item to the end
|
||||
$person["job"] = "developer"; // add new K-V pair
|
||||
|
||||
$count = count($fruits);
|
||||
$exists = in_array("apple", $fruits);
|
||||
sort($fruits);
|
||||
$keys = array_keys($person);
|
||||
$values = array_values($person);
|
||||
|
||||
echo nl2br("\n\n");
|
||||
?>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user