Home  >  Article  >  Backend Development  >  PHP curl opening problem_PHP tutorial

PHP curl opening problem_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:34:30682browse

Today I am working on a Sina login function. The curl_init() function needs to be used in the PHP SDK provided by Sina. When debugging, it reported that the curl_init() method cannot be found.

After searching, I learned that I need to enable the php extension of curl. So what is curl? What can be done?
A brief introduction, when we need to capture the data information of a website, we can use file(), file_get_contents() and other web page reading functions. Due to the proliferation of too many thief programs, some sites have implemented domain name restrictions. , thus making these file() functions inefficient or even invalid.
If you use curl to optimize it, you can achieve powerful and flexible functions such as forms, cookies, and verification.

Steps to enable curl

1. Output phpinfo under the localhost site to detect the location of php.ini
(Because when I turned on CURL, I configured php.ini in the php installation directory, and the result never took effect. Later, I checked phpinfo and found out that php.ini was redirected by me in the configuration file of apache
)
2. Open the php.ini file, search for php_curl.dll, delete the previous ";" after finding it, and restart apache
3. If the test still cannot find curl_init(), copy php_curl.dll in the ext directory in the php directory, and libeay32.dll, php5ts.dll, ssleay32.dll in the php directory
Go to c:windowssystem32 and restart apache
Verify whether the curl extension is enabled. You can search it in phpinfo()
or you can use the program to verify

<?<span php
</span><span //</span><span  1. 初始化 </span>
<span $ch</span> =<span  curl_init(); 
</span><span //</span><span  2. 设置选项,包括URL </span>
curl_setopt(<span $ch</span>, CURLOPT_URL, "http://www.jbxue.com"<span ); 
curl_setopt(</span><span $ch</span>, CURLOPT_RETURNTRANSFER, 1<span ); 
curl_setopt(</span><span $ch</span>, CURLOPT_HEADER, 0<span ); 
</span><span //</span><span  3. 执行并获取HTML文档内容 </span>
<span $output</span> = curl_exec(<span $ch</span><span ); 
</span><span //</span><span  4. 释放curl句柄 </span>
curl_close(<span $ch</span><span );  
</span><span $output</span> = curl_exec(<span $ch</span><span ); 
</span><span if</span> (<span $output</span> === <span FALSE</span><span ) { 
</span><span echo</span> "cURL Error: " . curl_error(<span $ch</span><span ); 
}</span>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/750881.htmlTechArticleToday I am making a Sina login function. The curl_init() function needs to be used in the PHP SDK provided by Sina. During debugging When reporting, the curl_init() method cannot be found. After searching, I learned that cur needs to be turned on...
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