Passing POST data from one web page to another with PHP

前端 未结 5 727
天命终不由人
天命终不由人 2020-12-19 05:44

Searching did not find a similar question, so: How can POST data used by PHP to generate one page be passed from that page to another PHP generated page? I have:

5条回答
  •  攒了一身酷
    2020-12-19 06:28

    Wez Furlong recently wrote the php5 version on his blog (titled HTTP post from php, without cURL):

    function do_post_request($url, $data, $optional_headers = null)
    {
    $params = array('http' => array(
    'method' => 'post',
    'content' => $data
    ));
    if ($optional_headers!== null) {
    $params['http']['header'] = $optional_headers;
    }
    $ctx = stream_context_create($params);
    $fp = @fopen($url, 'rb', false, $ctx);
    if (!$fp) {
    throw new Exception("Problem with $url, $php_errormsg");
    }
    $response = @stream_get_contents($fp);
    if ($response === false) {
    throw new Exception("Problem reading data from $url, $php_errormsg");
    }
    return $response;
    }
    

    In the post he mentions that he always has to look up how to do this. Funny because he's one of the core developers!

提交回复
热议问题