SHARE
TWEET

safe echo of query string

a guest Apr 29th, 2019 132 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top