Displaying a requested URL
Moderator: General Moderators
-
prejudged_fire
- Forum Newbie
- Posts: 15
- Joined: Sun Dec 18, 2005 6:28 pm
Displaying a requested URL
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.
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.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
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...
for more information read file_get_contents()
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);
}-
prejudged_fire
- Forum Newbie
- Posts: 15
- Joined: Sun Dec 18, 2005 6:28 pm
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.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Are you sure you are including http:// in the url?
works fine for me 
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);
}- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
-
prejudged_fire
- Forum Newbie
- Posts: 15
- Joined: Sun Dec 18, 2005 6:28 pm
Last edited by prejudged_fire on Mon Dec 19, 2005 10:08 am, edited 1 time in total.
-
prejudged_fire
- Forum Newbie
- Posts: 15
- Joined: Sun Dec 18, 2005 6:28 pm
-
prejudged_fire
- Forum Newbie
- Posts: 15
- Joined: Sun Dec 18, 2005 6:28 pm
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
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
-
prejudged_fire
- Forum Newbie
- Posts: 15
- Joined: Sun Dec 18, 2005 6:28 pm
this is the coding used for index.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>
<form action="index.php" method="POST">
<input type='text' name='url' value="http://">
<input type="submit" value="Go">
</body>
</html>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>- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
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
For the love of god use the edit button..
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..
-
prejudged_fire
- Forum Newbie
- Posts: 15
- Joined: Sun Dec 18, 2005 6:28 pm
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
-
prejudged_fire
- Forum Newbie
- Posts: 15
- Joined: Sun Dec 18, 2005 6:28 pm