1$post = [
2 'teste' => $_POST['teste']
3];
4httpPost('url.com', $post);
5// function
6function httpPost($url, $data)
7{
8 $curl = curl_init($url);
9 curl_setopt($curl, CURLOPT_POST, true);
10 curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
11 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
12 $response = curl_exec($curl);
13 curl_close($curl);
14 return $response;
15}
1// set post fields
2$post = [
3 'username' => 'user1',
4 'password' => 'passuser1',
5 'gender' => 1,
6];
7
8$ch = curl_init('http://www.example.com');
9curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
10curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
11
12// execute!
13$response = curl_exec($ch);
14
15// close the connection, release resources used
16curl_close($ch);
17
18// do anything you want with your response
19var_dump($response);
1 $post_data_arr = [
2 'f_name' => 'First',
3 'l_name' => 'Last',
4 ];
5
6 $url = 'http://example.com';
7 $curl = curl_init($url);
8 curl_setopt($curl, CURLOPT_POST, true);
9 curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data_arr);
10 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
11 $response = curl_exec($curl);
12 curl_close($curl);
13 print_r($response);
14