更新时间:2023-11-30 23:25:04
您可以尝试这一点,但也确保收听网址有一个处理程序来处理你的字preSS请求
端(使用 GET
methof)
函数curlAdduser($ strUrl)
{
如果(空($ strUrl))
{
回报错误:无效的URL给';
} $ CH = curl_init();
curl_setopt($ CH,CURLOPT_URL,$ strUrl);
curl_setopt($ CH,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ CH,CURLOPT_CONNECTTIMEOUT,30);
curl_setopt($ CH,CURLOPT_CUSTOMREQUEST,'GET');
$收益率= curl_exec($ CH);
curl_close($ CH);
返回$返回;
}
从外部站点调用函数:
curlAdduser(\"www.example.com/adduser?username=james&password=simpletext&email=myemail\"); 更新:是 POST
法
函数curlAdduser($ strUrl,$数据){
$栏='';
的foreach($数据,$关键=> $值){
$领域。= $键。 =。 $值。 '和;';
}
$栏= RTRIM($领域,'和;'); $ CH = curl_init();
curl_setopt($ CH,CURLOPT_URL,$ strUrl);
curl_setopt($ CH,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ CH,CURLOPT_CONNECTTIMEOUT,30);
curl_setopt($ CH,CURLOPT_POST,1);
curl_setopt($ CH,CURLOPT_POSTFIELDS,$领域);
$收益率= curl_exec($ CH);
curl_close($ CH);
返回$返回;
}
通话与数据的功能
$数据=阵列(
用户名= GT; 詹姆斯,
密码=> 的SimpleText
电子邮件=> 我的电子邮件
);
curlAdduser(www.example.com/adduser,$数据);
In Wordpress, i want to create New Users from external. I've found this is function in wordpress:
wp_create_user( $username, $password, $email );
So how can i run this function from external call please?
I mean, how to run this function from either:
www.example.com/adduser/?username=james&password=simpletext&email=myemail
.. from external website.
You may try this but also make sure that the listening url has a handler to handle the request in your WordPress
end (using GET
methof)
function curlAdduser($strUrl)
{
if( empty($strUrl) )
{
return 'Error: invalid Url given';
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $strUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
$return = curl_exec($ch);
curl_close($ch);
return $return;
}
Call the function from external site :
curlAdduser("www.example.com/adduser?username=james&password=simpletext&email=myemail");
Update : using POST
method
function curlAdduser($strUrl, $data) {
$fields = '';
foreach($data as $key => $value) {
$fields .= $key . '=' . $value . '&';
}
$fields = rtrim($fields, '&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $strUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$return = curl_exec($ch);
curl_close($ch);
return $return;
}
Call the function with data
$data = array(
"username" => "james",
"password" => "simpletext",
"email" => "myemail"
);
curlAdduser("www.example.com/adduser", $data);