Jump to content

fopen and file_get_contents alternatives


lip9000

Recommended Posts

Hey guys I've tried both fopen and file_get_contents in this function to get the contents of a URL, and both are rejected by my host (Godaddy).

 

Warning: fopen(): URL file-access is disabled in the server configuration i.....

 

Warning: file_get_contents(): URL file-access is disabled in the server configuration i....

 

The script pulls the title from a youtube page, it goes as follows:

 

$str = file_get_contents($url);

$begin = strpos($str, "<title>");
$end = strpos($str, "</title>");
$title = substr($str, $begin+17, $end-192);

 

What alternative functions can I use to get the contents of the file???

Link to comment
Share on other sites

Call me old fashioned, but you could always try the manual:

 

cURL

sockets

 

Now, i'm unsure if the setting allow_url_fopen needs to be on for the use of cURL/sockets (it appears to be off with your host) but either way i wouldn't be surprised if you can't use these either.

 

You might wish to contact your host and find out if the above setting can be changed.

 

 

Link to comment
Share on other sites

would this be correct?

 



<?php
$url = 'http://www.google.com/';

$ch = curl_init();

//Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//Set the URL
curl_setopt($ch, CURLOPT_URL, $URL);
//Execute the fetch
$data = curl_exec($ch);
//Close the connection
curl_close($ch);

//$data now contains the contents of $URL
print $data;
   ?>

 

I tried uploading and testing that but it just gives me a blank page, no errors though. I tried echo instead of print and that did nothing either.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.