0

誰か助けてくれませんか?

私は自分のサイトでphpスクリプトを作成しました。これは、取得データを受け取り、その取得データに基づいてtrueまたはfalseを返します。

完全に異なるサーバー上のphpを介してそのスクリプトを呼び出し、戻り値を保存する方法が必要です。

どうすればこれを行うことができますか?

また、POSTでもそれをどのように行うのですか?

4

2 に答える 2

0

cURLを使用して、他のサーバー上のスクリプトを呼び出したり、そのスクリプトにデータを投稿したりできます。

//set POST variables
$url = 'http://example.com/post.php';
$fields = array(
            'data1' => urlencode($data1),
            'data2' => urlencode($data2),
        );

//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);

詳細については、http://php.net/manual/en/ref.curl.phpを参照してください。

于 2012-10-07T09:09:21.043 に答える
0

このような何かがGETのためにそれを行います:

$response = file_get_contents('your_url_here');

そしてPOSTには、cURLを使用します。

于 2012-10-07T09:09:46.520 に答える