Advertisement
Guest User

echo

a guest
Oct 4th, 2015
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.73 KB | None | 0 0
  1. <?php
  2.  
  3. /* Simple php echo page for software programming exercise 1
  4.    Copyright Stephen Barrett
  5.  
  6.    You should have your client open a socket connection to port 80 of this site and attempt to
  7.    send text with the following shape:
  8.  
  9.    GET /%7eebarrett/lectures/cs4032/echo.php HTTP1.0\r\n
  10.  
  11.    If you are running a local server (such as php -S localhost:8000) then it would be something like:
  12.  
  13.    GET /echo.php HTTP1.0\r\n
  14.    
  15.    Different programming languages have different library support for sending http requests.
  16.    Don't use these! Use a raw TCP socket and send the string form above, read the response (a line)
  17.    and close.
  18.    
  19.    (see http://www.w3.org/Protocols/rfc2616/rfc2616.html for details of the HTTP/1.1 protocol)
  20.  
  21.     You should print out the server response to the terminal.
  22. */
  23.  
  24. //      ini_set('display_errors', 'On');
  25. //      error_reporting(E_ALL | E_STRICT);
  26.       if(isset($_GET['source'])) {
  27.         if ($_GET['source'] == "raw")
  28.            echo file_get_contents(basename($_SERVER['PHP_SELF']));
  29.         else
  30.            echo "<pre>" . htmlspecialchars(file_get_contents(basename($_SERVER['PHP_SELF']))) . "</pre>";
  31.       } else if (isset($_GET['message'])){
  32.         echo strtoupper( htmlspecialchars($_GET['message'])) . '\n';
  33.       } else {
  34. ?>
  35.       <html>
  36.         <head>
  37.           <title>Whoops: no message for me?</title>
  38.         </head>
  39.         <body>
  40.           <h1>Whoops: no message for me?</h1>
  41.           <p>If you are seeing this page then you have managed to call the echo server without
  42.           sending a parameter. Well done on getting this far, but now try to work out how to send
  43.           a text string to be converted to uppercase</p>
  44.         </body>
  45.       </html>
  46. <?php
  47.       }
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement