Skip to content

Instantly share code, notes, and snippets.

@jyxjjj
Created October 12, 2022 03:52
Show Gist options
  • Save jyxjjj/de36b5fdc45ff3f738066d88288dedea to your computer and use it in GitHub Desktop.
Save jyxjjj/de36b5fdc45ff3f738066d88288dedea to your computer and use it in GitHub Desktop.
cURL PHP GET POST
<?php
function GET($url, $user_agent = 'CURL', $proxy_type = CURLPROXY_SOCKS5_HOSTNAME, $proxy = null, $header = null, $timeout = 10)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
$header != null && curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$proxy != null && curl_setopt($ch, CURLOPT_PROXYTYPE, $proxy_type);
$proxy != null && curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_HEADER, false);
$file_contents = curl_exec($ch);
curl_close($ch);
return $file_contents;
}
<?php
function POST($url, $post_data = null, $user_agent = 'CURL', $proxy_type = CURLPROXY_SOCKS5_HOSTNAME, $proxy = null, $header = null, $timeout = 10)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
$post_data != null && curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$user_agent != null && curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
$header != null && curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$proxy != null && curl_setopt($ch, CURLOPT_PROXYTYPE, $proxy_type);
$proxy != null && curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_HEADER, false);
$file_contents = curl_exec($ch);
curl_close($ch);
return $file_contents;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment