Jump to content

Getting results from HTTP commands


Eiolon

Recommended Posts

I have a hardware device that I can send commands to by typing in a URL in the address bar.

 

One command tells me if the ports are in use:

 

http://admin:12345678@192.168.1.10/Set.cmd?CMD=GetPower

 

It returns the result:

 

p61=1,p62=1,p63=1,p64=1 

 

What I want to do is try and grab the result with PHP when the page loads so I can tell people if the port is turned on or off.

 

So "p61=1" means port 1 is turned ON.  If "p61=0" was displayed, it means port 1 is turned OFF.

 

I am not sure if it is even possible to grab the information using PHP or not.  Any place to start would be great!  Thanks!

Link to comment
Share on other sites

Here's one way you could do it. Use file_get_contents to grab the string of values, then explode it on the comma. Further explode each value on the equals sign and assign the port number as an array key, and the value as the value. Then you can access the value via the port number as the array key.

 

$str = 'p61=1,p62=1,p63=1,p64=1,p65=0,p66=0,p67=1'; // assumed to be the result of the call to file_get_contents() . . .
$arr = explode(',', $str);

foreach( $arr as $v ) {
   $tmp = explode('=', $v);
   $ports[$tmp[0]] = (int)$tmp[1];
}

 

var_dump($ports); returns:

 

[pre]array

  'p61' => int 1

  'p62' => int 1

  'p63' => int 1

  'p64' => int 1

  'p65' => int 0

  'p66' => int 0

  'p67' => int 1

[/pre]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.