title: How can I run a PHP script with cURL code in a Safari extension?
body: <p>I am trying to run a PHP bot function in a Safari extension.</p>
  
  <p>This is the HTML code I've tried to put together, but it's a mess of PHP, cURL, and HTML, and I don't really know what I'm doing.</p>
  
  <p>I've never attempted to use cURL before I got this code from <a href="http://www.barattalo.it/2010/08/09/send-push-notification-to-iphone-with-php-and-pushme-to/" rel="nofollow noreferrer">http://www.barattalo.it/2010/08/09/send-push-notification-to-iphone-with-php-and-pushme-to/</a>, and it seems like the extension stops working when I try to initiate $ch. That obviously defeats the whole purpose of the code, because I need it to run the cURL commands.</p>
  
  <p>Any tips to get this working?</p>
  
  <pre><code> 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) . '&amp;'.$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);
   }
  </code></pre>