In diesem PHP Snippet von Sick seht ihr, wie ihr Daten via POST an eine Webseite übertragen könnt.
PHP
- //set POST variables
- $url = 'http://localhost/post_recv.php';
- $data = array(
- 'var1' => 'val1',
- 'var2' => 'val2',
- );
- $data_string = '';
- //url-ify the data for the POST
- foreach ($data as $key => $value) {
- $data_string .= $key .'='. $value .'&';
- }
- rtrim($data_string,'&');
- //open connection
- $ch = curl_init();
- //set the url, number of POST vars, POST data
- curl_setopt($ch,CURLOPT_URL,$url);
- curl_setopt($ch,CURLOPT_POST,count($data));
- curl_setopt($ch,CURLOPT_POSTFIELDS,$data_string);
- //execute post
- $result = curl_exec($ch);
- //close connection
- curl_close($ch);
Termi