开发者

Curl stop browser sending Get Requests

开发者 https://www.devze.com 2023-04-13 04:50 出处:网络
I wrote this script $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $address); curl_setopt($ch, CURLOPT_USERAGENT, $useragent);

I wrote this script

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $address);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE)开发者_如何转开发;
curl_setopt($ch, CURLOPT_NOBODY, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_COOKIEJAR,$cookieFileLocation);
curl_setopt($ch, CURLOPT_COOKIEFILE,$cookieFileLocation);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 25); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);


$response = curl_exec($ch);  

echo ($response);

curl_close($ch);

When I execute the script the site will be loaded but also some other get requests are sent by the browser. How can I stop the browser sending more get requests? I want to follow the requests I write so I can see which request loads which part of the site. First I just want to see what gets loaded when I send the request I wrote.


I'm guessing you're trying to do some sort of proxy, using curl to fetch some other html page, and then forward it onto the browser? You will have to rewrite the HTML and CSS and JS in that page so that all requests for other resources (images, fonts, flash, etc...) point back at your server and your proxy script. Otherwise, if the HTML you're forwarding contains any absolute (and/or <base>'d) addresses, you will not be able to prevent the browser from reaching out and fetching those resources directly.


I am not completely sure what you are trying to achieve but the best bet would be to monitor when you get a request back from cURL and once these are retrieved successfully then you would then process them.

This cURL request would only be sent ONCE during the script loading as to send this multiple times you would need to use a loop such as a while or foreach to achieve this. No other GET requests would be sent from loading the PHP script provided.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号