配列があり、投稿リクエストを使用してこの配列を送信する必要があります。
この配列を文字列としてシリアル化し、配列全体を 1 つの post パラメーターとして送信する必要があります。
私はこの CURL に使用します。これは index.php コードです。
$name = array(2,3,"5.5");
$name = serialize($name);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://site.com/retrieve_post.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'name='.$name);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:19.0) Gecko/20100101 Firefox/19.0') );
$data = curl_exec($ch);
curl_close($ch);
これはretrieve_post.php
ファイルです:
$arr = unserialize($_POST['name']);
$hand = fopen("test.txt", "w+");
if (is_array( $arr )) {
fwrite($hand, "This is array");
}
else {
fwrite($hand, "Not array");
}
fclose($hand);
問題は、その後unserialize($_POST['name'])
、配列ではないことです。
ファイルには、test.txt
「配列ではありません」と書かれています。
なぜ、$arr
配列型ではないのですか? どこが間違っていますか?