'R98s', 'name' => 'Bob', 'content' => 'Hello'); ...">

Curl Release Message

<?php
$url = "http://website.com/folder/index.php";
$data = array('id' => 'R98s', 'name' => 'Bob', 'content' => 'Hello');

$handle = curl_init($url);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
curl_exec($handle);
?> 

This works fine, only 1 problem, id, as a way to get a response to the content from published data in a variable, and not show as if its page.

+3
source share
2 answers

Try the following:

        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE ); // return into a variable
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_POST, TRUE);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
        $result = curl_exec( $ch ); // run!
        curl_close($ch);

And never forget curl_close($handle);at the end.

+2
source

I always thought you needed it too

curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($handle)
0
source

Source: https://habr.com/ru/post/1735151/


All Articles