cURL是用來擷取網頁用的。
因為專題寫網頁有用到,所以紀錄一下安裝步驟。


1. Only install PHP with the zip’d binaries. Don’t use the installer. I recommend deleting your current PHP installation and reinstalling with the binaries. Downloading the latest PHP has the added benefit of ensuring its compatible with the version of cURL you’ll download later. (I installed to D:\apps\php and will use that path for the rest of this example)

2. Edit your php.ini file:

- set extensions_dir to d:\apps\php\extensions

- set register_globals to On

- set sessions.save_path to d:\apps\php\temp (you need to create that directory first)

3. Copy php4ts.dll (located in d:\apps\php\) to your Apache bin folder

4. Copy libeay32.dll and ssleay32.dll (located in d:\apps\php\dlls\) to c:\windows\system32

5. Download cURL for Windows at: http://curl.haxx.se/download.html. I chose the Win32 - Generic by J?Hartroth. I recommend getting the SSL version in case you ever need SSL. I unzipped cURL to d:\apps\curl and will use that path for the rest of this example

6. [SSL INSTALL ONLY] Download OpenSSL for Windows from http://curl.haxx.se/download.html. (Its near the bottom of the page). Extract libssl32.dll to d:\apps\curl

7. [Windows XP Install Only] Check to see if you have the following file: c:\windows\system32\msvcr70.dll. If not, search for it in Google and download it to system32. You may get error messages without it.

8. Uncomment the curl line in your php.ini file to enable curl: extension=php_curl.dll

9. Finally edit your Apache httpd.conf file to enable php:

- Uncomment: LoadModule php4_module d:/apps/php/sapi/php4apache2.dll

- Add Line: AddType application/x-httpd-php .php

Test with the following PHP code:

$url = “http://www.thinkgeek.com”;

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,$url);

curl_setopt($ch, CURLOPT_VERBOSE, 1);

curl_setopt($ch, CURLOPT_POST, 0);

curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

$returned = curl_exec($ch);

curl_close ($ch);

echo $returned;

SSL NOTE: I kept getting no response when I tried using curl with SSL urls. I found that adding the following solved the problem:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

I have read that the proper solution is to use the ca-bundle.crt file for curl to be able to verify certificates but I haven’t tried this yet:

curl_setopt($ch, CURLOPT_CAINFO, ‘drive:\pathto\ca-bundle.crt’);

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 athovamp 的頭像
    athovamp

    玉山銀行

    athovamp 發表在 痞客邦 留言(0) 人氣()