General get value from possible input sources


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

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.