Using header() to Send Raw Headers : header « HTML « PHP






Using header() to Send Raw Headers

 
<?php
  $num_to_guess = 42;
  $message = "";
  if (! isset ( $_POST ['guess'] )) {
    $message = "Welcome!";
  } else if ($_POST ['guess'] > $num_to_guess) {
    $message = $_POST ['guess'] . " is too big!";
  } else if ($_POST ['guess'] < $num_to_guess) {
    $message = $_POST ['guess'] . " is too small!";
  } else {
    header ( "Location:congrats.html" );
    exit ();
  }
  $guess = ( int ) $_POST ['guess'];
  $num_tries = ( int ) $_POST ['num_tries'];
  $num_tries ++;
  ?>
<html>
<head>
<title>A PHP Number Guessing Script</title>
</head>
<body>
 <?php print $message?> Guess: <?php print $num_tries?><br />
<form method="post" action="<?php
print $_SERVER ['PHP_SELF']?>">
<p><input type="hidden" name="num_tries"
  value="<?php
  print $num_tries?>" /> Number: <input
  type="text" name="guess" value="<?php print $guess?>" /></p>
</form>
</body>
</html>
  
  








Related examples in the same category

1.Changing the page type to CSV
2.Changing the page type to XML
3.Setting a Cookie Using the header() Function
4.Logged In with cookie
5.Forcing File "Save As" Downloads
6.Good and bad Location headers
7.If a User Is Not Logged in, the Login Form Is Loaded
8.Mime types
9.Setting character encoding
10.Sending an XML response
11.Sending Content Types Other Than HTML
12.Reading Queued Headers
13.Redirect header
14.Redirecting with query string variables