我可以使用 Ajax 发布到我网站中的一个 php 文件,但是当我尝试使用 php 发布到同一个 php 文件时,我的服务器似乎没有获取任何数据并且它不会发布这是我得到的 msg在服务器日志中:“POST /login_exec.php HTTP/1.0”302 447“-”“Mozilla/4.0(兼容;MSIE 6.0;Windows NT 5.1)”我尝试了很多不同的 curl 脚本,但我似乎找不到为什么它不起作用。这是我目前使用的代码 - (我尝试了很多不同的选项)
<?php
//create array of data to be posted
$post_data['username'] = 'yarden';
$post_data['password'] = 'yarden';
//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}
//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);
//create cURL connection
$curl_connection = curl_init('http://mydomain.org.il/login_exec.php');
//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
//perform our request
$result = curl_exec($curl_connection);
//show information regarding the request
print_r(curl_getinfo($curl_connection));
echo curl_errno($curl_connection) . '-' . curl_error($curl_connection);
//close the connection
curl_close($curl_connection);
?>
对不起我的英语,请帮助我:)谢谢