2

GREAT comment thread at: https://stackoverflow.com/a/6398220/1679026 gave me hope but I failed to solve my issue. When I use cURL to fetch the www.php.net page, it works so cURL works

I have a network-appliance that lives on a local LAN (http://192.168.1.117) here, or at my client site the devices (n) are on their LAN (173.18.13.xxx). From a Local_Browser_Address I can type "http://192.168.1.117/#diag/term&cmd=signage+sign+ALARM" and the network-appliance responds with a change to the "ALARM" state. <-- That is what I want to automate with one button!

On my web form I have $_POST PHP code to execute when the Alarm_Button is clicked. I want the user on my clients physical site to be able to click the_button on my web_form (www.mySite.com/index.php?option=com_rsform&formId=27) in -their browser- and have cURL code send/Post/execute that (http-ALARM) address/instruction string. Can I do this thing? No UI Required at or after address/instruction is sent.

I tried:

     $c = curl_init('http://192.168.1.117/u/r/l');
     curl_setopt($c, CURLOPT_HTTPHEADER, array('#diag/term&cmd=signage+sign+ALARM'));
     curl_exec($c);

AND

     $curl = curl_init();
     echo"<br>  the curl resource is ch --> $curl";
     curl_setopt ($curl, CURLOPT_URL, "http://192.168.1.117");
     curl_setopt ($curl, CURLOPT_POST, "/#diag/term&cmd=signage+sign+CELL_IN_ALARM");
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     $result = curl_exec ($curl);
     curl_close ($curl);
     echo"<br>  The RESULT (1) is --> $result";

No error message but no useful result.

First: I am afraid I am being stopped by the security restrictions like "no_outside_web_page_doing_junk_locally" kind of rules.

IF I have to create a local page on an internal web server, I can do this on another device on the same/adjacent network. But the problem remains for me, how to express the ip/command instruction in the cURL tools.

I have scoured the StackOverFlow information and it seems like I am close but missing the "glaring truth" somewhere!

Hope my challenge is worthy of your interest. Thank you. ---UPDATE---

HTTPFox capture of the POST events the "Sent" values (461) above and below the one (484) highlighted have respective POST Data of: {"version":"1.1","method":"unit.baseInfo","id":28,"params":[]} {"version":"1.1","method":"term.cmd","id":29,"params":["signage sign CELL_IN_ALARM"]} {"version":"1.1","method":"unit.baseInfo","id":30,"params":[]}

This shows Types application/jason and URLs of -http://192.168.1.117/jasonrpc-(jasonRemoteProcedureCall?)

Does this simplify or complicate my struggle?

-- New Update --

When I run the following code I get the php.net home page and a blank return "...is -->" for the second return...

// From http://www.tuxradar.com/practicalphp/15/10/2
  $curl1 = curl_init();
    curl_setopt ($curl1, CURLOPT_URL, "http://www.php.net");
    curl_setopt($curl1, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec ($curl1);
    curl_close ($curl1);
    print $result;
//====================
  $curl = curl_init();
    curl_setopt ($curl, CURLOPT_URL, "http://192.168.1.117");
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec ($curl);
    curl_close ($curl);
    //print $result;
  echo"<br>  The RESULT (1) is --> $result";

The first one is a www and the second one is the device on my network. Is this a primitive Network/Web conflict? Really appreciate the brain cycles here!

Community
  • 1
  • 1
  • Can you elaborate on what exactly is failing? Does curl throw an error, or does the request not hit the appropriate local address, or what? "No joy" is unhelpful. What output do your code snippets give? – Seth Battin Nov 16 '12 at 02:57
  • the curl resource is ch --> Resource id #163 The RESULT (1) is --> the curl resource (2) is ch --> Resource id #164 The RESULT (2) is --> – LongTimeHack Nov 16 '12 at 03:07
  • From the code: $curl = curl_init(); echo"
    the curl resource is ch --> $curl"; curl_setopt ($curl, CURLOPT_URL, "http://192.168.1.117"); curl_setopt ($curl, CURLOPT_POST, "/#diag/term&cmd=signage+sign+CELL_IN_ALARM"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec ($curl); curl_close ($curl); //print $result; echo"
    The RESULT (1) is --> $result";
    – LongTimeHack Nov 16 '12 at 03:07
  • AND the code: $c = curl_init('http://192.168.1.117/u/r/l'); echo"
    the curl resource (2) is ch --> $c"; curl_setopt($c, CURLOPT_HTTPHEADER, array('Host: /#diag/term&cmd=signage+sign+CELL_IN_ALARM')); // "/#diag/term&cmd=signage+sign+CELL_IN_ALARM"); $result = curl_exec($c); echo"
    The RESULT (2) is --> $result";
    – LongTimeHack Nov 16 '12 at 03:08
  • I was getting so little actual information back on the code processing it was hard to qualify, but "no joy" is essentially not helpful! :/ I appreciate your thoughts. – LongTimeHack Nov 16 '12 at 03:18

1 Answers1

1

You are thinking of CURLOPT_POSTFIELDS.

This can be used like

$ch = curl_init($site);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "field1=value1&field2=value2&field3=value3");
$chx = curl_exec($ch);

It should also be noted that CURLOPT_POST only takes TRUE or FALSE per the documentation found here

Steve
  • 2,936
  • 5
  • 27
  • 38
  • CURLOPT_POSTFIELDS looks like the right direction. My field1=value1&field2=value2&... for term&cmd=signage+sign+CELL_IN_ALARM seem to make sense as "field1=term&field2=cmd" but then I am at a loss on handling "=signage+sign+CELL_IN_ALARM" unless it is just another value? Appreciated. – LongTimeHack Nov 16 '12 at 18:04
  • when your form is handled, $_POST['cmd'] will be equal to "signage sign CELL_IN_ALARM" it seems like signage could be a class where sign is a method and CELL_IN_ALARM is an argument? I dunno, but the first part of my response is how it would be handled. It's just another value. – Steve Nov 16 '12 at 23:14
  • When I inspect the element (command input input#cmd.cmd) I found this: . How do I break those out to feed them to the CURLOPT_POSTFIELD fields? Thanks! – LongTimeHack Nov 17 '12 at 21:49