Runs the written php
file in terminal
php script.php
php
files served by web server such as apache
or nginx
in directories like htdocs
or /var/www/html
are interpreted by PHP runtime extension called by the webserver
$_POST
Access to data sent to server from client through HTTP POST
method
<?php
if (isset($_POST['data'])) {
echo $_POST['data'];
}
$_GET
Access to data sent to server from client through HTTP GET
method
<?php
if (isset($_GET['data'])) {
echo $_GET['data'];
}
$_REQUEST
Access to data sent to server from client through any HTTP method
if (isset($_REQUEST['data'])) {
echo $_REQUEST['data'];
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Number Form</title>
</head>
<body>
<form action="power.php" method="POST">
<label for="number">Enter a number:</label>
<input type="number" name="number" id="number" required>
<button type="submit">Submit</button>
</form>
</body>
</html>
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['number'])) {
$number = (int) $_POST['number'];
$result = $number ** 2;
echo "The square of $number is: $result";
} else {
echo "Invalid request.";
}
?>