Clean & Grab POST/GET/Referer Variable functions


/ Published in: PHP
Save to your folder(s)

This set of functions makes it quicker for me to code, might be useful to someone else =]


Copy this code and paste it in your HTML
  1. function clean($var){
  2.  
  3.  
  4. }
  5.  
  6. function grab_postvar($index, $clean = true){
  7.  
  8. return (isset($_POST[$index]) && !empty($index)) ? (($clean) ? clean($_POST[$index]) : $_POST[$index] ) : false ;
  9.  
  10. }
  11.  
  12. /* Usage: $post_variable = grab_postvar("id"); | Returns the variable else returns boolean false */
  13.  
  14.  
  15. function grab_getvar($index, $clean = true){
  16.  
  17. return (isset($_GET[$index]) && !empty($index)) ? (($clean) ? clean($_GET[$index]) : $_GET[$index] ) : false ;
  18.  
  19. }
  20.  
  21. /* Usage: $get_variable = grab_getvar("id"); | Returns the variable else returns boolean false */
  22.  
  23.  
  24. function grab_referer($default = NULL){
  25.  
  26. return (isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER'])) ? clean($_SERVER['HTTP_REFERER']) : ((is_null($default)) ? '/' : $default ) ;
  27.  
  28. }
  29.  
  30. /* Usage: $referer_url = grab_referer("index.php"); */

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.