- <?php
- /**
- * Get contents cURL
- *
- * @param string $url Source url
- * @param string $user_agent
- * @return string
- */
- function file_get_contents_curl($url, $user_agent)
- {
- // initialize cURL
- $curl = curl_init($url);
- curl_setopt_array($curl, array(
CURLOPT_USERAGENT => $user_agent,
CURLOPT_HEADER => false,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_FOLLOWLOCATION => true,
-
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => 2,
- ));
- // execute the request
- $data = curl_exec($curl);
- // fail if the request was not successful
- if ($data=== false) {
- curl_close($curl);
- return null;
- }
- return $data;
- }
Sunday, April 13, 2014
[PHP Programming] Get content using cURL
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment