Jump to content

Search the Community

Showing results for tags 'button post'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  1. Hello, PHP Friends! I wonder if somebody knows how to post or I better say call some URL like http://192.168.0.1/out.cgi?out1=1 from valid IP domain (server sees lan url) in background with Button click using form? For example to turn some device ON or OFF... I have tried with only PHP and also cURL but no luck <? //Check for status of device from xml (1 is Off & 0 is On) if ($xml->out1 == 1) { echo "<tr><td>OUT1</td><td><img src='images/red.png' alt='RED' height='23' width='23'></td><td><form method='post' action='index.php'><input type='hidden' value='out1' name='out1'><input type='submit' value='TURNON' name='TURNON'></form></td></tr>"; } else { echo "<tr><td>OUT1</td><td><img src='images/green.png' alt='GREEN' height='23' width='23'></td><td><form method='post' action='index.php'><input type='hidden' value='out1' name='out1'><input type='submit' value='TURNOFF' name='TURNOFF'></form></td></tr>"; } //cURL function to call URL with parameters function post_to_url($url, $data) { $fields = ''; foreach($data as $key => $value) { $fields .= $key . '=' . $value . '&'; } rtrim($fields, '&'); $post = curl_init(); curl_setopt($post, CURLOPT_URL, $url); curl_setopt($post, CURLOPT_POST, count($data)); curl_setopt($post, CURLOPT_POSTFIELDS, $fields); curl_setopt($post, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($post); curl_close($post); } //device URL $url = 'http://192.168.0.1/out.cgi'; //Turn on device $on = $_POST['name'] . '=0'; //Turn off device $off = $_POST['name'] . '=1'; //Check for Button action on user Click if(isset($_POST['TURNON'])) { post_to_url($url,$on); }elseif(isset($_POST['TURNOFF'])){ post_to_url($url,$off); }else{} ?> If I should use any other method, way, function, shell_exec etc..? Any suggestions, help is very welcome. Thank you.
×
×
  • 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.