網頁

2011年12月1日 星期四

php post

curl
【筆記】用PHP+cURL傳送Request (GET,POST或上傳檔案)至另一個網頁

managing curl output in php



  php 模拟post请求,并且接收POST数据后进行处理
PHP 接收 POST語法
$_POST["name"];
        // foreach ($postArr as $key => $value) {
        //     # code...
        //     $sarr[] = $key.'='.$value;
        // }

        //$options = array(CURLOPT_POSTFIELDS => IMPLODE('&',$sarr )); 
        CURLOPT_POSTFIELDS => http_build_query($postArr)

PHP 5: Send HTTP post request with file_get_contents

               // $url = 'http://server.com/path';
                $data = array('email' => 'value1', 'name' => 'value2');
             
                // use key 'http' even if you send the request to https://...
                $options = array('http' => array(
                    'method'  => 'POST',
                    'content' => http_build_query($data)
                ));
                $context  = stream_context_create($options);
                $result = file_get_contents($url, false, $context);
             
                var_dump($result);
echo htmlspecialchars($_POST['email']) ; //remove HTML tag
echo htmlspecialchars($_POST['name']) ; //remove HTML tag


沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。