Ec (2); & nbsp; copy the code functionhttpget ($ url, $ followredirectstrue) {global $ final_url; $ url_parsedparse_url ($ url ); if (empty ($ url_parsed [scheme]) {& nbsp; script ec (2); script
The Code is as follows: |
|
Function httpget ($ url, $ followredirects = true ){ Global $ final_url; $ Url_parsed = parse_url ($ url ); If (empty ($ url_parsed ['scheme ']) { $ Url_parsed = parse_url ('HTTP: // '. $ url ); } $ Final_url = $ url_parsed; $ Port = $ url_parsed ["port"]; If (! $ Port ){ $ Port = 80; } $ Rtn ['url'] ['Port'] = $ port; $ Path = $ url_parsed ["path"]; If (empty ($ path )){ $ Path = "/"; } If (! Empty ($ url_parsed ["query"]) { $ Path. = "? ". $ Url_parsed [" query "]; } $ Rtn ['url'] ['path'] = $ path; $ Host = $ url_parsed ["host"]; $ Foundbody = false; $ Out = "get $ path http/1.0 "; $ Out. = "host: $ host "; $ Out. = "user-agent: mozilla/5.0 (windows; u; windows nt 5.1; en-us; rv: 1.8.1) gecko/20061010 firefox/2.0 "; $ Out. = "connection: close "; If (! $ Fp = @ fsockopen ($ host, $ port, $ errno, $ errstr, 30 )){ $ Rtn ['errornumber'] = $ errno; $ Rtn ['errorstring'] = $ errstr; } Fwrite ($ fp, $ out ); While (! @ Feof ($ fp )){ $ S = @ fgets ($ fp, 128 ); If ($ s = ""){ $ Foundbody = true; Continue; } If ($ foundbody ){ $ Body. = $ s; } Else { If ($ followredirects) & (stristr ($ s, "location :")! = False )){ $ Redirect = preg_replace ("/location:/I", "", $ s ); Return httpget (trim ($ redirect )); } $ Header. = $ s; } } Fclose ($ fp ); Return (trim ($ body )); |