PHP Post Request inside a POST Request

前端 未结 3 2106
余生分开走
余生分开走 2021-01-25 08:03

There is a contact form which current action is http://www.siteA.com/ContactInfo.php, it sends fields and values. In ContactInfo.php, i just catch the values and se

3条回答
  •  野性不改
    2021-01-25 08:37

    You can try something like this using cURL (http://www.php.net/manual/en/curl.examples.php) ..

    $sub_req_url = "http://www.siteB.com/Reg.aspx";
    
    $ch = curl_init($sub_req_url);
    $encoded = '';
    
    // include GET as well as POST variables; your needs may vary.
    foreach($_GET as $name => $value) {
      $encoded .= urlencode($name).'='.urlencode($value).'&';
    }
    
    foreach($_POST as $name => $value) {
      $encoded .= urlencode($name).'='.urlencode($value).'&';
    }
    
    // chop off last ampersand
    $encoded = substr($encoded, 0, strlen($encoded)-1);
    
    curl_setopt($ch, CURLOPT_POSTFIELDS,  $encoded);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_exec($ch);
    curl_close($ch);
    

    Shamly

提交回复
热议问题