1$ch = curl_init();
2curl_setopt($ch, CURLOPT_URL,"http://www.example.com/process.php");
3curl_setopt($ch, CURLOPT_POST, 1);
4curl_setopt($ch, CURLOPT_POSTFIELDS,$vars); //Post Fields
5curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
6
7$headers = [
8 'X-Apple-Tz: 0',
9 'X-Apple-Store-Front: 143444,12',
10 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
11 'Accept-Encoding: gzip, deflate',
12 'Accept-Language: en-US,en;q=0.5',
13 'Cache-Control: no-cache',
14 'Content-Type: application/x-www-form-urlencoded; charset=utf-8',
15 'Host: www.example.com',
16 'Referer: http://www.example.com/index.php', //Your referrer address
17 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) Gecko/20100101 Firefox/28.0',
18 'X-MicrosoftAjax: Delta=true'
19];
20
21curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
22
23$server_output = curl_exec ($ch);
24
25curl_close ($ch);
26
27print $server_output ;
1<?php
2
3$post = [
4 'username' => 'user1',
5 'password' => 'passuser1',
6 'gender' => 1,
7];
8$ch = curl_init();
9curl_setopt($ch, CURLOPT_URL, 'http://www.domain.com');
10curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
11curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
12$response = curl_exec($ch);
13var_export($response);
14
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);
1PHP cURL GET Request
2A GET request retrieves data from a server. This can be a website’s HTML, an API response or other resources.
3
4<?php
5
6$cURLConnection = curl_init();
7
8curl_setopt($cURLConnection, CURLOPT_URL, 'https://hostname.tld/phone-list');
9curl_setopt($cURLConnection, CURLOPT_RETURNTRANSFER, true);
10
11$phoneList = curl_exec($cURLConnection);
12curl_close($cURLConnection);
13
14$jsonArrayResponse - json_decode($phoneList);
1function getUrl($url){
2 $ch = curl_init($url);
3 curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
4 $response = curl_exec($ch);
5 curl_close($ch);
6 return $response;
7}
1// Initialize Curl
2 $curl = curl_init();
3 curl_setopt($curl, CURLOPT_URL, "https://coinmarketcap.com/"); // set live website where data from
4 curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); // default
5 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); // default
6 $content = curl_exec($curl);
7
8 preg_match_all('!<p color="text3" class="sc-AxhUy bzeXdk coin-item-symbol" font-size="1">(.*?)</p>!', $content, $matches);
9
10 var_dump($matches);