Finding Values on POST & GET

Discussion in 'PHP' started by AT-XE, Oct 5, 2008.

  1. #1
    Hello DPers,
    I am just wondering if let's say we have an array like:
    <?php $valuearray = array("request1","request2","etc"); ?>
    PHP:
    and we want to detect if there are any other parameters in a post request via a function that returns true if there are other parameters and false if not.

    Example call of that function:
    <?php
    $valuearray = array("request1","request2","etc");
    if(detectpost($valuearray)) {
    echo 'there are other parameters on POST.';
    } else {
    echo 'there are no other parameters on POST.';
    }
    ?>
    PHP:
    Thank you,
    -AT-XE
     
    AT-XE, Oct 5, 2008 IP
  2. GuitarFix

    GuitarFix Peon

    Messages:
    37
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Well.. it's not very hard.
    Just try to find element which not exists in $_POST array and return "false"..
     
    GuitarFix, Oct 5, 2008 IP
  3. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #3
    
    
    function detectpost($arrayvars,$_POST){
      foreach($_POST as $item){
        if(!in_aray($item,$arrayvars)){ return true;}
      }
      return false;
    }
    
    PHP:
    Call it like:

    
    <?php
    $valuearray = array("request1","request2","etc");
    if(detectpost($valuearray,$_POST)) {
    echo 'there are other parameters on POST.';
    } else {
    echo 'there are no other parameters on POST.';
    }
    ?>
    
    PHP:
    Peace,
     
    Barti1987, Oct 5, 2008 IP
    AT-XE likes this.
  4. fireworking

    fireworking Peon

    Messages:
    460
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thank you azizny. I needed that also.
     
    fireworking, Oct 5, 2008 IP
  5. AT-XE

    AT-XE Peon

    Messages:
    676
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thank you guys!
    azizny, +Rep Added
     
    AT-XE, Oct 6, 2008 IP