ゴジラ

PHP POST Example

In the example below,

We also return/display the response from the POST by storing the result in the variable $response and then we export/display it with var_export($response).

<?php
$post = [
    'username' => 'user1',
    'password' => 'passuser1',
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.domain.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
$response = curl_exec($ch);
var_export($response);
?>

Last modified: December 06 2019 14:21:55