Posted By

luizlopes on 05/27/08


Tagged

get session post input cookie variable Value general sources


Versions (?)

General get value from possible input sources


 / Published in: PHP
 

This can be used as a general function to get the value stored in any of the possible input sources. use

  1. /* Get a variable from the possible input sources. */
  2. function getVar($var_name) {
  3. if (!empty($_GET[ $var_name ])) {
  4. return $_GET[ $var_name ];
  5. } elseif (!empty($_POST[ $var_name ])) {
  6. return $_POST[$var_name ];
  7. } elseif (!empty($_SESSION[ $var_name ])) {
  8. return $_SESSION[ $var_name ];
  9. } elseif (!empty($_COOKIE[ $var_name ])) {
  10. return $_COOKIE[ $var_name ];
  11. } else {
  12. return null;
  13. }
  14. }

Report this snippet  

You need to login to post a comment.