2 Little questions in PHP

Please tell me which method is mostly accepted for getting the contents of another page.
file_get_contents or curl.

One more thing, what is the PHP Code to check the any server has curl and file_get_contents disabled, because I want to do another operation I mean echo or something else, if they are disabled.

It depends what content your planning on pulling, cURL is usually used for API’s and secure connections and file_get_contents is mostly used for grabbing a dump of a file to change and/or update.

The function function_exists will allow you to check for missing functions, see the example below…

if (function_exists('curl_init')) {
    // Run the cURL connection
} else {
    // Display and error
if (function_exists('file_get_contents')) {
    // Run the file_get_contents code
} else {
    // Display and error

You can also use fopen but your php.ini has to have allow_url_fopen on. I would use cURL instead though.

Simple Example:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.site.com');
$result = curl_exec($ch);

echo $result;