Deciding what to do based on request method : _SERVER « Form « PHP






Deciding what to do based on request method

 
<?php if ($_SERVER['REQUEST_METHOD'] == 'GET') { ?>
<form action="<?php echo $_SERVER['SCRIPT_NAME'] ?>" method="post">
What is your first name?
<input type="text" name="first_name" />
<input type="submit" value="Say Hello" />
</form>
<?php } else {
    echo 'Hello, ' . $_POST['first_name'] . '!';
}
?>
  
  








Related examples in the same category

1.$_SERVER extracts valuable server- and script-related information
2.Adjusting behavior based on an environment variable
3.Log use IP address
4.Getting Times and Dates of Files: $_SERVER['SCRIPT_FILENAME']
5.PHP $_SERVER Arguments
6.superglobal variables
7.Output file time
8.Some Common $_SERVER Elements