Workaround for URL access in PHP


#1

Hi there,

I’ve read the wiki to find an alternative to URL access; I tried the cURL alternative, I still can’t get it to work.

I’m not a PHP coder and I’m trying to do one of those “lifestream” pages (basically, an RSS aggregator).

This is the source code I’m using: http://adactio.com/extras/stream/stream.phps

Any ideas?
Thanks,
-dinis


#2

Jeremy’s code uses the DOM extension’s DOMDocument() function to access the file by creating an object to manipulate. Specifically, it calls the load() method of the object, and it appears that method needs URL file access. I’m not well-versed in OOP, but it would seem to me that you would need to figure out a way of creating your own load() method that uses cURL, and then apply that to the existing object.


si-blog | Keystone Websites
Save $97 on yearly plans with promo code [color=#CC0000]SCJESSEY97[/color]


#3

[quote]I’ve read the wiki to find an alternative to URL access; I tried the cURL alternative, I still can’t get it to work.

I’m not a PHP coder and I’m trying to do one of those “lifestream” pages (basically, an RSS aggregator). [/quote]
Here is a very basic use of curl to read URL contents. I use this to pull XML from a url and pass it to a DOM object among other purposes. I didn’t look at your specific code and situtation, but you should be able to just place this function in the page or code that needs it, or create a file to include in each piece of code that needs it. Sorry, it isn’t in an object class, but really isn’t complicated enough to need it either.

[code]function get_url_contents($url)
{
$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);

// return the results
return $file_contents;
}
[/code]Call this in the format of
$xml = get_url_contents(“http://www.someurl.com”)


find/offer services free
http://www.TheHelpfulNeighbor.com
Codes:THNMax ($97) THNMaxHDD (+100%) THNMaxBW (+100% txfr) THNMaxDomains (5 free) THNBalance (20% HD&BW, 1 Domain+IP +$16)