Displaying a requested URL
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
After you've captured the data, your going to have to change the instances of
http://theirdomain.com/ to http://yourdomain.com?request=http://theirdomain.com
When you would pass the request variable to your curl function so it knows which page to load. Of course your going to have to ignore style sheets, images, etc.. which is why I said a clever regex. Try posting in the Regex Forum for more help.
http://theirdomain.com/ to http://yourdomain.com?request=http://theirdomain.com
When you would pass the request variable to your curl function so it knows which page to load. Of course your going to have to ignore style sheets, images, etc.. which is why I said a clever regex. Try posting in the Regex Forum for more help.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
ask and you shall receive
Code: Select all
<?php
/****************************************************************
/* phphttp function by Burrito and Twindagger
/* Modify at will
/* Last Modified 04/22/2004
/***************************************************************/
//$urlwhere must be like http://www.somehost.com/somedir/somedoc.html
function phphttp($urlwhere, $posts = FALSE, $referer = "http://www.somedomain.com/")
{
if ($posts === FALSE && ($ret = @file($urlwhere)) !== FALSE)
{
return implode("", $ret);
}
else
{
$method = "GET";
if ($posts)
$method = "POST";
$tmp = explode("/", $urlwhere);
$host = $tmp[2];
$target = str_replace("http://" . $host, "", $urlwhere);
if (strlen($target) == 0)
$target = "/";
$request = "$method $target HTTP/1.1\r\n";
$request .= "Host: $host\r\n";
$request .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)\r\n";
$request .= "Keep-Alive: 300\r\n";
$request .= "Connection: Close\r\n";
$request .= "Referer: $referer\r\n";
$request .= "Cache-Control: max-age=0\r\n";
if ( $method == "POST" )
{
$length = strlen( $posts );
$request .= "Content-Type: application/x-www-form-urlencoded\r\n";
$request .= "Content-Length: $length\r\n";
$request .= "\r\n";
$request .= $posts;
}
else
$request .= "\r\n";
$header = "";
$response = "";
// connect
if (!($socket=fsockopen($host,80,$errno,$errstr))) return $errstr;
else {
socket_set_timeout($socket,10);
// send request
fwrite($socket,$request);
// get header
do
{
$header = "";
do $header.=fread($socket,1); while (!preg_match('/\\r\\n\\r\\n$/',$header));
} while (strpos($header, "HTTP/1.1 1") === 0);
//echo "<pre>" . $header . "</pre><br>";
// check for chunked encoding
if (preg_match('/Transfer\\-Encoding:\\s+chunked\\r\\n/',$header))
do {
$byte = "";
$chunk_size="";
do {
$chunk_size.=$byte;
$byte=fread($socket,1);
} while ($byte!="\r"); // till we match the CR
fread($socket, 1); // also drop off the LF
$chunk_size=hexdec($chunk_size); // convert to real number'
if ($chunk_size > 2048)
{
while ($chunk_size > 0)
{
$size = ($chunk_size > 2048 ? 2048 : $chunk_size);
$response.=fread($socket, $chunk_size);
$chunk_size -= $size;
}
}
else
$response.=fread($socket,$chunk_size);
fread($socket,2); // ditch the CRLF that trails the chunk
} while ($chunk_size); // till we reach the 0 length chunk (end marker)
else {
// check for specified content length
if (preg_match('/Content\\-Length:\\s+([0-9]*)\\r\\n/',$header,$matches)) {
if ($matches[1] > 2048)
{
$c_size = $matches[1];
while ($c_size > 0)
{
$size = ($c_size > 2048 ? 2048 : $c_size);
$response.=fread($socket, $c_size);
$c_size -= $size;
}
}
else
$response=fread($socket,$matches[1]);
} else {
// not a nice way to do it (may also result in extra CRLF which trails the real content???)
while (!feof($socket)) $response .= fread($socket, 2048);
}
}
// close connection
fclose($socket);
}
return $response;
}
}
/* example usage
echo phphttp("http://www.yahoo.com");
*/
?>-
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
-
prejudged_fire
- Forum Newbie
- Posts: 15
- Joined: Sun Dec 18, 2005 6:28 pm
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
As stated, an iframe is far simpler than using PHP. I mean if all your doing is putting another sites pages into a framed section of your site - do you really need PHP? Why not let the user's browser do all the legwork (and save yourself the extra bandwidth) unless you are actively manipulating that content in some (which incidentally can be interpreted in the wrong way by some people who think they alone have the right to manipulate pages they create).
Iframe makes a lot of sense unless there are specific needs it jus will not resolve...
Iframe makes a lot of sense unless there are specific needs it jus will not resolve...
-
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
something like this should work:
untested:
untested:
Code: Select all
<script>
function changeIt()
{
var val = document.MyForm.page.value;
document.getElementById('fr').src = val;
}
</script>
<form name="MyForm">
<input type="text" name="page"><input type="button" value="Update Page" onClick="changeIt()">
</form>
<iframe src="http://www.yahoo.com" width="500" height="500" id="fr"></iframe>-
prejudged_fire
- Forum Newbie
- Posts: 15
- Joined: Sun Dec 18, 2005 6:28 pm