|
Search:
Advanced search
|
Browse by category:
|
Contact Us |
How you replace your php fopen function with curl? |
|||||
Now a days the fopen() function is disabled from all of the servers for security reason.
If you want to use the remote file inclusion in your web page you have to replace the fopen() function code with curl. Here is the procedure. Suppose here is an sample code using fopen. It will include the remote file content of the url http://www.someurl.com. <?php if ($fp = fopen('http://www.someurl.com/', 'r')) { $content = ''; // keep reading until there's nothing left while ($line = fread($fp, 1024)) { $content .= $line; } echo $content; } else { echo "error"; } ?> Now here is the replacement of the above code with curl. <?php $url = "http://www.someurl.com/" // initialize a new curl resource $ch = curl_init(); // set the url to fetch curl_setopt($ch, CURLOPT_URL, $url); //excluding the headers curl_setopt($ch, CURLOPT_HEADER, 0); // return the value instead of printing the response to browser curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //take the content as a instance $file = curl_exec($ch); //close the session and free all resources curl_close($ch); ?> That's all. |
|||||
Powered by
Deru Communications (Webhosting Knowledgebase)