Justtechjobs.com Find a programming school near you






Online Campus Both


php3-list | 200003

Re: [PHP3] "Stealing" an HTML page From: Ciprian (gzero <email protected>)
Date: 03/21/00

Tuesday, March 21, 2000, 06:47, Matt G. Ellis wrote:
> I'd like to know how i could go about creating a gateway, like anonimizer,
> that would take a URL, Fetch it, and then send it to the web browser that
> sent of the request, but from my script, not from the actual site you
> requested.

You can always do a HTTP connection, issue a GET request, put the
results in a file, strip leading HTTP headers and HTML <head></head>
and starting <body>, then output everything else.

Of course, you realize you should also do some tag escaping on the
fetched page, otherwise a malicious user of your system could design
a page of his own that, when displayed by your script, could do bad
things on *your* server, just as if it were your page.

Here's a simple PHP script that will start a connection, get the
resource and simply echo it out. It's straightforward and you
shouldn't have any problems with it.

<?php
$ht=fsockopen('www.domain.com',80) or die('*** FAILED ***');
fputs($ht,"GET /path/file.html?var=value HTTP/1.0\n");
fputs($ht,"Host: www.domain.com\n");

// Browser ID, might want to use a well known one to be sure no
// rejections occur
fputs($ht,"User-Agent: Mozilla/4.7 [en] (Win98; I) **YEAH RIGHT**\n");

// This mentions the page which led you to the page you're trying to
// fetch, put their own homepage in to be sure.
fputs($ht,"Referer: http://www.domain.com\n");

// following stuff added just to be sure --some scripts/servers might check
fputs($ht,"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*\n");
fputs($ht,"Accept-Charset: iso-8859-1,*,utf-8\n");
fputs($ht,"Accept-Encoding: gzip\n");
fputs($ht,"Accept-Language: en\n");

// EOF
fputs($ht,"\n.");

// request sent, stand by for response:
while (!feof($ht))
{
  $s=fgets($ht,4096);
// You might wanna do some ereg_replace here, change < and > into &lt;
// and &gt; Also, I output everything, you might want to check for the
// first occurance of <body, then start echo'ing.
  echo $s;
}

//Bye-bye!
fclose($ht);
?>

-- 
PHP 3 Mailing List <http://www.php.net/>
To unsubscribe, send an empty message to php3-unsubscribe <email protected>
To subscribe to the digest, e-mail: php3-digest-subscribe <email protected>
To search the mailing list archive, go to: http://www.php.net/mailsearch.php3
To contact the list administrators, e-mail: php-list-admin <email protected>