Click to See Complete Forum and Search --> : Retieve remote webpage source code


BoR|S
11-19-2003, 05:45 AM
Let's say I have a remote page: www.website.com/somepage.html

How do I remotly view it's source code? By opening a socket and using GET header to recieve the source? Another way?
I need it to be something like www.mysite.com/showsource.php?page=www.website.com/somepage.html
Is that possible at all?

EDIT: I was suggested in another forum to use the following:

$f=file("http://".$_GET['page']);

So I made this showsource.php file:

<?php
$f=file("http://".$_GET['page']);
?>

But when I run it, I get the following error:

Warning: php_hostconnect: connect failed in /home/boris/htdocs/showsource.php on line 2

Warning: file("http://www.website.com/somepage.html") - Bad file descriptor in /home/boris/htdocs/showsource.php on line 2

What's the problem in here?

pyro
11-19-2003, 07:44 AM
Take a look at http://us3.php.net/filesystem. Does your php.ini file have allow_url_fopen set to On? If not, you won't be able to open remote files like that.

BoR|S
11-19-2003, 08:00 AM
Originally posted by pyro
Take a look at http://us3.php.net/filesystem. Does your php.ini file have allow_url_fopen set to On? If not, you won't be able to open remote files like that.

Assuming it does not, is there any other way doing that?

pyro
11-19-2003, 08:14 AM
Not that I'm aware of. You can get information on using remote files at http://us3.php.net/manual/en/features.remote-files.php.

TheBearMay
11-19-2003, 09:02 AM
If you just want to see the source code you can try this (I got this over at http://javascript.internet.com/ some time ago):

<html>
<head>

<script language="JavaScript">
function viewSource() {
document.getSource.view.value="Please wait!";
setTimeout("document.getSource.view.value='View Source!'",6000);
window.location.href= "view-source:" + document.getSource.url.value;
return false;
}
</script>
</head>

<body>

<center>
Type in a full URL and click "View Source"
<br>
<br>
<form name=getSource onSubmit="return viewSource();">
<input type=text name=url value="http://">
<br>
<br>
<input type=submit name=view value="View Source">
</form>
</center>
</body>
</html>

BoR|S
11-19-2003, 09:12 AM
Thanks for that solution. The only problem I have with it, is the fact I want to see the source in my browser. and not in my default text editor...