我想設置一個自動使用代理的網頁。這裏是我的腳本:使用php curl代理瀏覽網站
<?
$url = 'http://www.sciencedirect.com/science/jrnlallbooks/a/fulltext';
$proxy = '200.93.148.72:3128';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_TIMEOUT, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt");
$curl_scraped_page = curl_exec($ch);
echo $curl_scraped_page;
?>
我可以打開網頁,並在標題顯示:
HTTP/1.0 200 OK日期:週五,2012年11月23 18點46分41秒格林尼治標準時間的Last-Modified:週五, 23 Nov 2012 18:46:41 GMT Set-Cookie:MIAMISESSION = 86e5ecb0-359b-11e2-b116-00000aab0f6c:3531149201;路徑= /;域= .sciencedirect.com; Set-Cookie:USER_STATE_COOKIE =;到期日=星期四,1970年1月1日23:59:59 GMT;路徑= /;域= .sciencedirect.com; Set-Cookie:SD_REMOTEACCESS =;到期日=星期四,1970年1月1日23:59:59 GMT;路徑= /;域= .sciencedirect.com;設置Cookie:MIAMIAUTH = 6c1869e3dd5d3ca5644fdd359099d551fee57ff4f19a0d9e30c92bcc3f4cdcb755a638c57790c6f118d4a8601a914733e770454895a95214fd2a92b748418c15aabbe7e39dbfe22d18a337761caf3eebb621aa3f17803d29fa1a241d10f4aad71e83423e9562a1ec67194a18c7a016cd36828cdb6ccdaef46d038a2ee15429cd0ee88a636ec51602cee8d34e3397f0c720230f6ab68fbc74c285431372f89886ba1bbbb03f6873e2804f1577f52679f16123dd0c07d70ab0b92145c1c383e4155512e57b8da9452ad570394af0c66b0859739b1e77c2d98372d5a1b978828531f3a042a816bf4a9edbe45d4f9197a685aa1506ae57ec1593efd428842244a96f9d2033b43ccf50a14843907943eb57b7c9dd1bef11603f9e686aad6847870ac6fec520209a31df9efb3d0ee4e24341c4c5dd6c12060a6a624c3ff60ec16286f7cb6c3839f8f375c00c836958eada8d4900baa294fa3645c02f1b3ac78c7bc78bc2d79f5f4e038b6ae465d63f0100a53731ec826eba3c6f8f648bf03d6ac7d450788f0362055ca413073d9333348cacdc6e4d6222a420a78620a968b185954fcc76b3a9a63f2e62f9;路徑= /;域= .sciencedirect.com; Set-Cookie:TARGET_URL = fcf74dd786744d87fbaaaf8652a764ab4a79b0d3ed681139e9106923760631052596d348948479933da48b3723069bbf09065290c950dc02c1f0d1436659ad5a;路徑= /;域= .sciencedirect.com;設置Cookie:MIAMIAUTH = 6c1869e3dd5d3ca5644fdd359099d551fee57ff4f19a0d9e30c92bcc3f4cdcb755a638c57790c6f118d4a8601a914733e770454895a95214fd2a92b748418c15aabbe7e39dbfe22d18a337761caf3eebb621aa3f17803d29fa1a241d10f4aad71e83423e9562a1ec67194a18c7a016cd36828cdb6ccdaef46d038a2ee15429cd0ee88a636ec51602cee8d34e3397f0c720230f6ab68fbc74c285431372f89886ba1bbbb03f6873e2804f1577f52679f16123dd0c07d70ab0b92145c1c383e4155512e57b8da9452ad570394af0c66b0859739b1e77c2d98372d5a1b978828531f3a042a816bf4a9edbe45d4f9197a685aa1506ae57ec1593efd428842244a96f9d2033b43ccf50a14843907943eb57b7c9dd1bef11603f9e686aad6847870ac6fec520209a31df9efb3d0ee4e24341c4c5dd6c12060a6a624c3ff60ec16286f7cb6c3839f8f375c00c836958eada8d4900baa294fa3645c02f1b3ac78c7bc78bc2d79f5f4e038b6ae465d63f0100a53731ec826eba3c6f8fe5378db869312c80a0addc0d8946f7f6552daa333f2e38da51e23c1d44ae41176c1b2e70f7b144f63a44c25741cd0126;路徑= /;域= .sciencedirect.com;內容類型:text/html過期時間:星期二,01一月1980 05:00:00 GMT X-RE-Ref:0 19194695服務器:www.sciencedirect.com P3P:CP =「IDC DSP LAW ADM DEV TAI PSA PSD IVA IVD CON HIS TEL OUR DEL SAM OTR IND OTC「不同:接受編碼,用戶代理X緩存:來自alejandria.ufps.edu.co的MISS X緩存查詢:來自alejandria.ufps.edu.co:3128的HIT Via :1.0 alejandria.ufps.edu.co(魷魚/ 3.0.STABLE15)代理連接:關閉
但是,該代理僅適用於此頁面。當我點擊此頁面上的其他鏈接時,沒有加載代理。請幫我解決這個問題。如何提高我的腳本?我想整個網站(所有鏈接)使用代理。如何設置?
而不是設置一個PHP代理你有沒有考慮讓你的web服務器處理代理? – PeeHaa
在資源管理器中設置代理很容易。但我想讓網頁內的腳本使用代理。然後其他人也可以通過我設置的代理訪問鏈接 – user1847875