473,326 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Retrieve and display 3rd party pages

Hi,

I'm wondering if you can show me an example php page that allows me to
retrieve and display 3rd party pages. I.e.,

when my php script is called as http://site/path/getit.php?file_key
it can retrieve from http://3rd.party/path2/name-with-file_key.htm
and display the result back to the browser.

I don't know php, and start to learning it. So I hope you can give me a full
php page, not a segment. I don't think it'd be too long though. Luckily, I'm
a programmer, so you don't need to comment it much, unless it is too
convoluted.

Further, if you can throw in handling of gzipped files, that'd be super.

If you have Firefox, it can automagically gunzipped gzipped files, like

http://www.gnu.org/software/bash/manual/bashref.html.gz

So I hope the script http://site/path/getit.php?bashref

can display the content of

http://www.gnu.org/software/bash/manual/bashref.html.gz

thanks
--
Tong (remove underscore(s) to reply)
http://xpt.sourceforge.net/
--
Posted via a free Usenet account from http://www.teranews.com

Oct 29 '06 #1
2 1750
Hi,

You could fetch a remote URL using PHP's URL wrappers. For example,
readfile can stream the contents of a remote URL:

readfile('http://site/content/page.html');

You could also do this with mod_proxy:

ProxyPass /my/mirror/ http://site/content/

Requests for /my/mirror/* will be internally sent to the remote site.
If the page contains internal links that use absolute URLs, you may
want to use mod_proxy_html to rewrite those URLs or use an output
buffer handler. More info on using mod_proxy_html:

<http://www.wlug.org.nz/ApacheReverseProxy>

You could also use a proxy application such as PHP Proxy
(www.phpproxy.com).

Since many browsers can automatically decompress gzip-compressed
content, you wouldn't need to worry about decompressing it yourself. If
you still wanted to do this however, you could use a shell command.
Some code to do that:

<?

// Sample usage:
//
// zcatUrl('http://site/file.html.gz')
//
// That will decompress the remote URL and stream content
// to the browser.

function zcatUrl($url)
{
$errors = tempnam('/tmp', 'zcatUrl-');
$cmd = 'wget -O - ' . escapeshellarg($url) .
' 2' . escapeshellarg($errors) . ' | zcat';
passthru($cmd, $exitCode);

if ($exitCode != 0) {
$msg = "Command \"$cmd\" failed with exit code $exitCode";
$err = false;
if (is_file($errors)) {
$err = file_get_contents($errors) or
trigger_error("Failed to read file $errors.");
}
$msg .= $err !== false ? ": $err" : '.';
trigger_error($msg);
}

if (is_file($errors)) {
unlink($errors) or
trigger_error("Failed to delete file $errors");
}
}

?>

* Tong * wrote:
Hi,

I'm wondering if you can show me an example php page that allows me to
retrieve and display 3rd party pages. I.e.,

when my php script is called as http://site/path/getit.php?file_key
it can retrieve from http://3rd.party/path2/name-with-file_key.htm
and display the result back to the browser.

I don't know php, and start to learning it. So I hope you can give me a full
php page, not a segment. I don't think it'd be too long though. Luckily, I'm
a programmer, so you don't need to comment it much, unless it is too
convoluted.

Further, if you can throw in handling of gzipped files, that'd be super.

If you have Firefox, it can automagically gunzipped gzipped files, like

http://www.gnu.org/software/bash/manual/bashref.html.gz

So I hope the script http://site/path/getit.php?bashref

can display the content of

http://www.gnu.org/software/bash/manual/bashref.html.gz

thanks
--
Tong (remove underscore(s) to reply)
http://xpt.sourceforge.net/
--
Posted via a free Usenet account from http://www.teranews.com
Oct 29 '06 #2
On Sat, 28 Oct 2006 22:12:45 -0700, petersprc wrote:
You could fetch a remote URL using PHP's URL wrappers. For example,
readfile can stream the contents of a remote URL:

readfile('http://site/content/page.html');

You could also do this with mod_proxy...

Since many browsers can automatically decompress gzip-compressed
content, you wouldn't need to worry about decompressing it yourself.
First of all, thanks a lot for this comprehensive reply. You've even
covered issues that I hadn't thought about. thanks!

Just for the archive, following your advice, and scripts found in
http://ca.php.net/readfile
I hacked the following php script, which tested ok:

<?php
header("Content-Type: text/html");
header("Content-Encoding: x-gzip");

set_time_limit(0);

ob_start();
readfile('http://rute.2038bug.com/index.html.gz');
// use @ to hide 'nothing to flush' errors
@ob_flush();

$content = ob_get_contents();
ob_end_clean();
?>
--
Tong (remove underscore(s) to reply)
http://xpt.sourceforge.net/
--
Posted via a free Usenet account from http://www.teranews.com

Oct 29 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: David Potahisnsky | last post by:
I have ASPX page with DataGrid object. To fill this object I use DataTable that contain result of stored procedure. In my case it's about 300 rows. I would like to display this table with...
5
by: Emmett Power | last post by:
Hi, I use Access to send emails through SMTP. I'd like to mirror the process and retrieve emails from my SMTP/Pop3 server without the intermediary of Outlook. I don't want to spend a lot of...
3
by: Richard Thornley | last post by:
Hello, I was just been given a project and I have some questions on how to accomplish the first part of the task. If a user sends an email to a specific email address I need to detect...
5
by: Martin Moser | last post by:
Does somebody knows, if theres a way to display any file (tiff, doc, pdf, .....) "inline" on an asp.net site? What I want to do is, to display a file, which is stored in the DB, and some...
1
by: John Phelan-Cummings | last post by:
When I add the name of a new individual in a, bound form, it will not display that person’s name in a label control of a second unbound form. I have a scheduling program that I am working on. ...
1
by: Lyners | last post by:
What I need - To retrieve the server name that the ASP application is running on. Why - Our current intranet is on a network where we have users that are on a domain and some that are not. Using...
8
by: Yoshitha | last post by:
Hi I want to Extracet(retrieve) data from some of websites and the retrieved data has to be saved in excel or.csv files. I need to develop this in ASP.net(using C#.net Vs 2003). Can any...
3
by: ipramod | last post by:
Hi, I have a code snippet C# when executed gives the following exception on IE. ___________________________________________________________________ Unable to retrieve the user sid from...
3
by: John Kotuby | last post by:
Hi all, Within an IFRAME of a standard site constructed of mostly static HTM type pages, I am calling up one page from a large ASP.NET 3.5 site. I have precompiled the ASP.NET site and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.