繁体   English   中英

如何在Safari扩展程序中运行带有cURL代码的PHP脚本?

[英]How can I run a PHP script with cURL code in a Safari extension?

我正在尝试在Safari扩展中运行PHP机器人功能。

这是我试图组合在一起的HTML代码,但是它是一堆PHP,cURL和HTML,我真的不知道自己在做什么。

在从http://www.barattalo.it/2010/08/09/send-push-notification-to-iphone-with-php-and-pushme-to/获得此代码之前,我从未尝试使用cURL ,而当我尝试启动$ ch时,该扩展似乎停止工作。 这显然破坏了代码的全部目的,因为我需要它来运行cURL命令。

有任何技巧可以使它正常工作吗?

 function performCommand(event)
 {    if (event.command === "sendLink") { 
pushMeTo($u,$t,$s);      }


 function pushMeTo($widgeturl, $text, $signature)
 { $agent = "Mozilla/5.0 (windows; U; Windows NT 6.0; en-US; rv:1.9.0.12) Gecko/2009070611 Firefox/3.0.12";
  $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $widgeturl);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_USERAGENT, $agent);
  $page = curl_exec($ch);
   preg_match("/form action=\"(.*?)\"/", $page, $form_action);
   preg_match("/textarea name=\"(.*?)\"/", $page, $message_field);
   preg_match("/input type=\"text\" name=\"(.*?)\"/", $page, $signature_field);

  $ch = curl_init();

  $strpost = $message_field[1].'=' . urlencode($text) . '&'.$signature_field[1].'=' . urlencode($signature);
   curl_setopt($ch, CURLOPT_POSTFIELDS, $strpost );
   curl_setopt($ch, CURLOPT_URL, $form_action[1]);
   curl_setopt($ch, CURLOPT_POST, 1);
   curl_setopt($ch, CURLOPT_HEADER, 0);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_USERAGENT, $agent);    
  $page = curl_exec($ch);
 }

您将无法按照自己的方式做自己想做的事。 在他的评论中,zneak是绝对正确的。 您的扩展程序在客户端运行,而PHP在服务器端运行。 您的Javascript不知道如何编写PHP代码。

或者,您的扩展程序可以将Ajax请求触发到可以运行PHP代码的URL。 我在我的一个扩展中执行此操作,我必须拨打服务电话。 效果很好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM