Page 1 of 3
Displaying a requested URL
Posted: Sun Dec 18, 2005 6:34 pm
by prejudged_fire
I want to have an input box where a user can type in a URL and then display that website's content in a designated area of my website but still stay on MY domain name. For example:
http://www.mysite.com
Welcome to My Website
enter URL:
http://www.somesite.com/
Then, when they click the "submit" button,
Welcome to My Website
-------------------------------------
Contents of
http://www.somesite.com/ displayed here.
But I want the user to stay on the mysite.com url. I guess this is kinda hard to explain but if any of you know what Im talking about, please help me ok? thanks.
Posted: Sun Dec 18, 2005 6:39 pm
by John Cartwright
So let me get this straight: you want to input a url via a form and grab the contents of that webpage to display on a section of your webpage?
If thats the case it is very simple. I am assuming you understand the use of $_POST and such...
Code: Select all
if (!empty($_POST['url'])) {
//grab contents of page
$contents = @file_get_contents($_POST['url']);
//if file_getg_contents() fails echo error instead of result
echo (!$contents ? 'Could not find the requested page '. $_POST['url'] : $contents);
}
for more information read
file_get_contents()
Posted: Sun Dec 18, 2005 6:46 pm
by prejudged_fire
well yes you understand what I mean and yes I understand $_POST. However that code simply displays Could not find the requested page no matter what url you input. I tested it with
http://www.yahoo.com/ and it could not find it.
Posted: Sun Dec 18, 2005 7:04 pm
by John Cartwright
Are you sure you are including http:// in the url?
Code: Select all
$_POST['url'] = 'http://www.yahoo.com';
if (!empty($_POST['url'])) {
//grab contents of page
$contents = @file_get_contents($_POST['url']);
//if file_getg_contents() fails echo error instead of result
echo (!$contents ? 'Could not find the requested page '. $_POST['url'] : $contents);
}
works fine for me

Posted: Sun Dec 18, 2005 7:06 pm
by prejudged_fire
yes im sure
Posted: Sun Dec 18, 2005 7:07 pm
by John Cartwright
Temporarly remove the @ before file_get_contents to see what the actual error is then
Posted: Sun Dec 18, 2005 7:07 pm
by prejudged_fire
Posted: Sun Dec 18, 2005 7:08 pm
by prejudged_fire
Parse error: parse error, unexpected '<' in /home/freehost/t35.com/y/o/youcantseeme/index.php on line 21
Posted: Sun Dec 18, 2005 7:10 pm
by prejudged_fire
wait actually this is the error
Warning: file_get_contents(): URL file-access is disabled in the server configuration in /home/freehost/t35.com/y/o/youcantseeme/index.php on line 15
Warning: file_get_contents(
http://www.yahoo.com): failed to open stream: no suitable wrapper could be found in /home/freehost/t35.com/y/o/youcantseeme/index.php on line 15
Could not find the requested page
http://www.yahoo.com
Posted: Sun Dec 18, 2005 7:13 pm
by prejudged_fire
this is the coding used for index.html
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<form action="index.php" method="POST">
<input type='text' name='url' value="http://">
<input type="submit" value="Go">
</body>
</html>
this is the code for index.php
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
Welcome to Youcantseeme.com!<br>
<hr>
<?php
$_POST['url'] = 'http://www.yahoo.com';
if (!empty($_POST['url'])) {
//grab contents of page
$contents = file_get_contents($_POST['url']);
//if file_getg_contents() fails echo error instead of result
echo (!$contents ? 'Could not find the requested page '. $_POST['url'] : $contents);
}
?>
</body>
</html>
Posted: Sun Dec 18, 2005 7:16 pm
by John Cartwright
The message is exactly what it sais.. the host has disabled the use of grabbing content from other sites via file_get_contents();
Try doing this
Code: Select all
$url= $_POST['url'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec ($ch); # This returns HTML
curl_close ($ch);
echo $content;
For the love of god use the edit button..
Posted: Mon Dec 19, 2005 10:07 am
by prejudged_fire
ok sorry about the bumping. That time it worked. But is there a way to remain on my website even when the user clicks on a link? If you havent already guessed, I am trying to make a site similar to Sneakysurf.com where you will remain on the sneakysurf server while viewing other pages.
Posted: Mon Dec 19, 2005 10:21 am
by Maugrim_The_Reaper
iframe? Can't think of anything else outside file_get_contents() and that your host seems to have disabled. An iframe may just do the trick - but the user will be connecting directly to that site for request - so what you would have is basically your site acting as a wrapper around its content.
Posted: Mon Dec 19, 2005 10:28 am
by John Cartwright
I've done this before without an iframe using curl, but you require some clever regex to modify the links and develop a way of passing the requested page around.
Posted: Mon Dec 19, 2005 10:42 am
by prejudged_fire
ok so how do i go about doing that?
BTW i am using a different host now that doesnt disable the use of grabbing contents of other urls