Advertisement
Guest User

safe echo of query string

a guest
Apr 29th, 2019
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.53 KB | None | 0 0
  1. <html>
  2.  
  3. <head>
  4.     <title>Safe Echoing of Query String Parameters</title>
  5. </head>
  6. <body>
  7.     City: <?php safe_echo('city', 'your hometown') ?>
  8. </body>
  9. </html>
  10. <?php
  11. /**
  12.  * Paste me at the bottom of your page or make a file and require_once()
  13.  *
  14.  * <?php safe_echo('city', 'Your Town'); ?>
  15.  *
  16.  * @param $param
  17.  * @param string $default
  18.  */
  19. function safe_echo($param, $default = '')
  20. {
  21.     $value = $default;
  22.  
  23.     if (!empty($_REQUEST[$param]))
  24.         $value = htmlspecialchars($_REQUEST[$param]);
  25.  
  26.     echo $value;
  27. }
  28. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement