PHP curl post登录到wordpress
我随后使用php_curl登录到wordpress,就我使用WAMP(apache/php)而言,它工作得很好 但是,当涉及到专用服务器上的IIS时,它什么也不返回 我已经编写了以下函数,该函数在我的本地wamp上运行良好,但当部署到客户端的专用windows服务器2k3时,它就不工作了。请帮帮我PHP curl post登录到wordpress,php,curl,Php,Curl,我随后使用php_curl登录到wordpress,就我使用WAMP(apache/php)而言,它工作得很好 但是,当涉及到专用服务器上的IIS时,它什么也不返回 我已经编写了以下函数,该函数在我的本地wamp上运行良好,但当部署到客户端的专用windows服务器2k3时,它就不工作了。请帮帮我 function post_url($url, array $query_string) { //$url = http://myhost.com/wptc/sys/wp/wp
function post_url($url, array $query_string)
{
//$url = http://myhost.com/wptc/sys/wp/wp-login.php
/* $query_string = array(
'log'=>'admin',
'pwd'=>'test',
'redirect_to'=>'http://google.com',
'wp-submit'=>'Log%20In',
'testcookie'=>1
);
*/
//temp_dir is defined as folder = path/to/a/folder
$cookie= temp_dir."cookie.txt";
$c = curl_init($url);
if (count($query_string))
{
curl_setopt ($c, CURLOPT_POSTFIELDS,
http_build_query( $query_string )
);
}
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_COOKIEFILE, $cookie);
//curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 1);
//curl_setopt($c, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt($c, CURLOPT_TIMEOUT, 60);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); //return the content
curl_setopt($c, CURLOPT_COOKIEJAR, $cookie);
//curl_setopt($c, CURLOPT_AUTOREFERER, 1);
//curl_setopt($c, CURLOPT_REFERER, wp_admin_url);
//curl_setopt($c, CURLOPT_MAXREDIRS, 10);
curl_setopt($c, CURLOPT_HEADER, 0);
//curl_setopt($c, CURLOPT_CRLF, 1);
try {
$result = curl_exec($c);
}
catch (Exception $e)
{
$result = 'error';
}
curl_close ($c);
return $result; //it return nothing (empty)
}
其他事实
快速思考:检查以确保temp_dir.“cookie.txt”可由IIS写入。我自己设法修复了它,这是wordpress中的一些小修复,而不是任何IIS或PHP特定信息 我在下面的部分修改了wp_redirect()(刚刚注释了主要部分)来修复它
function wp_redirect($location, $status = 302) {
global $is_IIS;
$location = apply_filters('wp_redirect', $location, $status);
$status = apply_filters('wp_redirect_status', $status, $location);
if ( !$location ) // allows the wp_redirect filter to cancel a redirect
return false;
$location = wp_sanitize_redirect($location);
/*
if ( $is_IIS ) {
status_header($status);
header("Refresh: 0;url=$location");
} else {
if ( php_sapi_name() != 'cgi-fcgi' ) {
status_header($status); // This causes problems on IIS and some FastCGI setups
}
header("Location: $location", true, $status);
}
*/
header("Location: $location", true, $status);
}