Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 24th, 2012  |  syntax: None  |  size: 0.66 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. PHP how to handle _GET/_POST without duplicating the code base
  2. if($_POST)
  3. {
  4. //then work with the post data
  5. }
  6. if($_GET)
  7. {
  8. //then work with the get data
  9. }
  10.        
  11. function doOperation($var)
  12. {
  13.    //then work with the var data
  14. }
  15.  
  16. if(isset($_POST))
  17. {
  18.    doOperation($_POST);
  19. }
  20.  
  21. if(isset($_GET))
  22. {
  23.    doOperation($_GET);
  24. }
  25.        
  26. function process($params)
  27. {
  28.   //then work with the params
  29. }
  30.        
  31. if(isset($_POST))
  32. {
  33.   process($_POST);
  34. }
  35. if(isset($_GET))
  36. {
  37.   process($_GET);
  38. }
  39.        
  40. if($_SERVER["REQUEST_METHOD"] == "POST") {
  41. $_GET = $_POST;
  42. }
  43.        
  44. if($_POST)
  45.    $varToUse = $_POST;
  46.  
  47. else if($_GET)
  48.    $varToUse = $_GET;
  49.  
  50. else
  51.    $varToUse = 'default case';
  52.  
  53. //> Process with $varToUse;