Click to See Complete Forum and Search --> : Reading files on other domains


bokeh
02-12-2005, 02:59 PM
I want to read from a file on another domain. Is this possible?

I tried:

$file = file ('http://www.the_other_domain');

without any luck.

Jona
02-12-2005, 03:34 PM
Did you get any errors? Try this:


readfile("http://www.site.com/file.txt");


The remote host could possibly be denying requests from specific referrers (or have "hot linking" disabled).

bokeh
02-12-2005, 05:20 PM
Hi! Thanks for your input. Got it working now with the following syntax.

<?php
$form = "<form action=\"\" method=\"post\">\n" .
"Enter a URL\n" .
"<input type=\"text\" name=\"file\" value=\"http://\" tabindex=\"1\" />\n" .
"<input id=\"submit\" type=\"submit\" value=\"Look at the source code\" tabindex=\"1\" />\n\n";
if (empty ($file)) {
print ("$form");
}else{
$ok = @($file = file_get_contents ("$file"));

if (!$ok) {
echo "<p>It appears that URL isn't valid! Please try again<br />$form</p>";
} else {
$file = str_replace ('<', '&lt;', $file);
$file = str_replace ('>', '&gt;', $file);
print ("<pre>$file</pre>");
}
}
?>

It's just a little script that lets you look behind the scenes at a website using a browser without having to contend with the default actions of the browser like redirection, frames, etc.

Jona
02-12-2005, 05:22 PM
Might try using htmlspecialchars instead of manually replacing <'s and >'s.