Re: How to make a directory / file only available to registered users using PHP code?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Apr 7, 2008 at 11:56 AM, Rian Hidayanto <rian.smart@xxxxxxxxx> wrote:
> hi,
>
>  I want to build PHP code, so that only registered users are able to
>  download the file.
>
>  (So that other users cannot download the file using direct url
>  "http:\\www.abcd.org\downloaddir\setup.exe" )

    This is just to get you started.  Polishing,
modifying/customizing, and sanitizing, you're on your own.

<?php
// download.php
session_start();

if(!isset($_SESSION['username'])) {
    die("Unauthorized access.");
}

// Keep the directory out of the web root.
$download = '../downloads/download.exe';

$filename = basename($download);

header("Pragma: public")
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=".$filename.";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".sizeof($download);
readfile($download);
exit(0);

?>


-- 
</Daniel P. Brown>
Ask me about:
Dedicated servers starting @ $59.99/mo., VPS starting @ $19.99/mo.,
and shared hosting starting @ $2.50/mo.
Unmanaged, managed, and fully-managed!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux