RE: phpweb / do_download.php
| From: | James Cox | Date: | Tue, 14 May 2002 21:49:20 +0000 |
| Subject: | RE: phpweb / do_download.php | ||
| References: | 1 | Groups: | php.mirrors |
| Request: | Send a blank email to php-mirrors+get-10180@lists.php.net to get a copy of this message | ||
Jim,
do you think that the log_download.php would be better on master.php.net?
James
> -----Original Message-----
> From: Gabor Hojtsy [mailto:gabor@hojtsy.hu]
> Sent: Tuesday, May 14, 2002 10:46 PM
> To: php-mirrors@lists.php.net
> Subject: cvs: phpweb / do_download.php
>
>
> goba Tue May 14 17:46:19 2002 EDT
>
> Modified files:
> /phpweb do_download.php
> Log:
> Reorganize download stuff, put log thing to a shutdown function
>
>
> Index: phpweb/do_download.php
> diff -u phpweb/do_download.php:1.7 phpweb/do_download.php:1.8
> --- phpweb/do_download.php:1.7 Wed Nov 7 02:47:42 2001
> +++ phpweb/do_download.php Tue May 14 17:46:17 2002
> @@ -1,29 +1,47 @@
> <?php
>
> -if (!isset($HTTP_REFERER)) {
> - $HTTP_REFERER="-";
> -}
> -
> +// If there is no file, then drop out an invalid file error message
> if (!isset($download_file)
> || !file_exists("distributions/$download_file")) {
> exit("Invalid file requested for download!");
> }
>
> +// Redirect to the particular file
> header("Location:
> http://$SERVER_NAME/distributions/$download_file");
>
> -$remote_addr = $HTTP_X_FORWARDED_FOR ? $HTTP_X_FORWARDED_FOR :
> $REMOTE_ADDR;
> +// Register the log function as a shutdown function to let the
> +// download starts before the log activates. This way if the
> +// "log server" does not work, downloads are still working
> +register_shutdown_function("log_download");
> +
> +// Log downloads in a shutdown function (do not disturb download)
> +function log_download ()
> +{
> + global $HTTP_REFERER, $HTTP_X_FORWARDED_FOR,
> + $REMOTE_ADDR, $SERVER_NAME;
>
> -$remote_log =
> - @fopen("http://www.php.net/log_download.php".
> - "?download_file=" . urlencode($download_file).
> - "&mirror=" . urlencode($SERVER_NAME).
> - "&user_referer=" . urlencode($HTTP_REFERER).
> - "&user_ip=" . urlencode($remote_addr),
> - 'r');
> + // Default referer
> + if (!isset($HTTP_REFERER)) {
> + $HTTP_REFERER = "-";
> + }
>
> -if ($remote_log) {
> - fread($remote_log, 1024);
> - fclose($remote_log);
> + // Figure out true remote address
> + $remote_addr = $HTTP_X_FORWARDED_FOR ? $HTTP_X_FORWARDED_FOR
> : $REMOTE_ADDR;
> +
> + // Try to open remote log on php.net
> + $remote_log =
> +
> @fopen("http://www.php.net/log_download.php".
> + "?download_file=" . urlencode($download_file).
> + "&mirror=" . urlencode($SERVER_NAME).
> + "&user_referer=" . urlencode($HTTP_REFERER).
> + "&user_ip=" . urlencode($remote_addr),
> + 'r');
> +
> + // If we can open it, read from it, and close (jut to make
> sure it runs)
> + if ($remote_log) {
> + fread($remote_log, 1024);
> + fclose($remote_log);
> + }
> }
>
> ?>
>
>
>