Home  >  Article  >  Backend Development  >  PHP curl modifies website request headers

PHP curl modifies website request headers

WBOY
WBOYOriginal
2016-07-25 09:12:531673browse

Example, php curl modifies website request headers, including useragent, header information, etc.

Code:

  1. for ($i = 0; $i < 5; $i++) {

  2. task();
  3. }

  4. //Modify the access request header

  5. function task() {
  6. $url = "http://www.xxx.com/?fromuid=272539";
  7. $ip = "100.100.".rand(1, 255)." .".rand(1, 255);
  8. $headers = array("X-FORWARDED-FOR:$ip");
  9. $curl = curl_init($url);
  10. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers) ;
  11. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  12. curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0");
  13. $src = curl_exec($curl);
  14. curl_close($curl);
  15. }
  16. ?>

Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn