This example describes how PHP generates the Curl command line. Share to everyone for your reference, specific as follows:
Example:
Curl "HTTP://LOCALHOST/OTHER/SERVERINFO.PHP?DD=DDD"-H "host:localhost"-H "connection:keep-alive"-H "Cache-control: Max-age=0 "-H" accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 "-H" User-Agent: mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/43.0.2357.132 safari/537.36 "-H" dnt:1 "-H" accept-encoding:deflate , SDCH "-H" accept-language:zh-cn,zh;q=0.8,en;q=0.6 "-H" cookie:name=richie; Email=richie@qq.com "
The specific code is as follows:
function Getcurlcommand () {try {if (php_sapi_name () = = ' Error cli ') {throw new Exception ("CLI");
} $curlCommand = ' curl ';
$postData = $getData = ';
if ($_get) {$gets = Http_build_query ($_get); $getData. = Strpos ($curlCommand, '? ') ' & '. $gets: '? '.
$gets;
} if ($_server[' request_method '] = = ' POST ') {$posts = Http_build_query ($_post); $postData = ' d '. $posts.
'"'; } $path = Isset ($_server[' script_name '])?
$_server[' Script_name ']: $_server[' php_self ']; $curlCommand. = ' "'." http://{$_server[' Http_host ']}. $path. $getData.
'"';
if ($postData) {$curlCommand. = $postData;
} $headers = Array ();
if (function_exists (' getallheaders ')) {$headers = Getallheaders (); else {foreach ($_server as $name => $value) {if (substr ($name, 0, 5) = = ' Http_ ') {$headers [str_replace (', '-', Ucwords (Strtolower (Str_replace (' _ ', ', ', substr ($name, 5)))]
= $value; $headers as $key =>$value) {if ($key = = ' accept-encoding ') $value = Str_replace (' gzip, ', ' $value); $curlCommand. = '-h '. $key. ':' . $value.
'"';
return $curlCommand;
catch (Exception $e) {return $e->getmessage (); } echo Getcurlcommand ();
I hope this article will help you with your PHP programming.