使用 cURL,(如何)可以在远程页面上执行 PHP 命令并将其作为字符串变量返回?
我想使用 cURL 执行以下操作:
登录到我的 Wordpress 站点,执行我自己的 PHP 代码并将其保存到变量中:
$code_to_execute_remotely = wp_create_nonce('my_form');
$ch =curl_init();
curl_setopt($ch, CURLOPT_URL, 'www.mywordpresssite.com');
curl_setopt($ch, CURLOPT_SOMEMYSTERIOUSFUNCTION, $code_to_execute_remotely); $resulting_variable = curl_exec($ch);然后在第二次 cURL 执行中使用该变量:
curl_setopt($ch, CURLOPT_MYSECONDFUNCTION, $resulting_variable);
$second_ececution = curl_exec($ch);
curl_close($ch);
当然,我使用了虚拟代码来简化事情。其他功能(登录远程站点等)没有问题,只需远程执行该代码并将其结果作为可用变量返回,这就是我所需要的。由于我对 cURL 不太熟悉,因此我可能正在尝试超出其范围的东西,在这种情况下,我将非常感激知道什么替代方案可以实现这一目标。
What I want to do using cURL:
Login to my Wordpress site, execute my own PHP code and save it to a variable:
$code_to_execute_remotely = wp_create_nonce('my_form');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'www.mywordpresssite.com');
curl_setopt($ch, CURLOPT_SOMEMYSTERIOUSFUNCTION, $code_to_execute_remotely);
$resulting_variable = curl_exec($ch);Then use that variable in a 2nd cURL execution:
curl_setopt($ch, CURLOPT_MYSECONDFUNCTION, $resulting_variable);
$second_ececution = curl_exec($ch);
curl_close($ch);
I've used dummy code to simplify things of course. The other functionality (logging into the remote site, etc.) is no problem, just executing that code remotely and returning its results as a usable variable, that's all I need. Since I'm not terribly familiar w/ cURL, it's possible I'm attempting something beyond its bounds, in which case I'd be very thankful to know what alternative could achieve this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在远程站点上使用 php eval 函数:
http://php.net/manual/en /function.eval.php
编辑完整说明:
在本地服务器上:
在receiver.php 中的远程服务器上:
注意:
On the remote site use the php eval function:
http://php.net/manual/en/function.eval.php
Edit with full explanation:
On your local server:
On the remote server in receiver.php:
Notes: