Hello, I have this code: <?php $sitemap = "http://www.mysitehere/sitemap.xml"; // change the location if needed $xmlDoc = new DOMDocument(); $xmlDoc->load($sitemap); $x = $xmlDoc->getElementsByTagName("url"); $size=0; foreach ($x AS $item){ $size++; } $xmlDoc->load($sitemap); $y = $xmlDoc->getElementsByTagName("url"); $string = "Location: "; $randomURL = rand(1, $size); $i=1; foreach ($y As $p) { if($i==$randomURL) { $toOpen = $p->getElementsByTagName("loc"); $toOpenURL = $toOpen->item(0)->nodeValue; $string = $string.$toOpenURL; header($string); } $i++; } ?> PHP: How do I make the $sitemap read rss.php ? This is a very old code I used... and I remember that the code above can actually work on http://www.mysitehere/rss.php so it redirects all users into the URL inside the /rss.php
Here is a another code for reading rss using SimpleXml . I hope it will help you ,there is no need for the 20$ <?php $RSS_content = file_get_contents('http://www.mysitehere/rss.php'); $Xml = new SimpleXmlElement($RSS_content); $size=0; foreach($Xml ->channel->item as $entry){ $size++; } $string = "Location: "; $randomURL = rand(1, $size); $i=1; foreach ($Xml ->channel->item as $entry) { if($i==$randomURL) { $string = $string.$entry->link; header($string); } $i++; } ?> PHP:
file_get_contents will not work if allow_url_fopen is off. This is the case with quite a few web hosting companies for security reasons. If it doesn't work you can use curl instead.