PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > How to make a directory / file only available to registered users using PHP code?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
How to make a directory / file only available to registered users using PHP code?

Réponse
 
LinkBack Outils de la discussion
Vieux 07/04/2008, 16h56   #1
Rian Hidayanto
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut How to make a directory / file only available to registered users using PHP code?

hi,

I put a file "setup.exe" in a directory "downloaddir\"

I want to build PHP code, so that only registered users are able to
download the file.

How to make the directory / files only available to registered users using
PHP code?

(So that other users cannot download the file using direct url
"http:\\www.abcd.org\downloaddir\setup.exe" )


TIA
Rian

  Réponse avec citation
Vieux 07/04/2008, 17h17   #2
Jason Pruim
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] How to make a directory / file only available to registered users using PHP code?


On Apr 7, 2008, at 11:56 AM, Rian Hidayanto wrote:
> hi,
>
> I put a file "setup.exe" in a directory "downloaddir\"
>
> I want to build PHP code, so that only registered users are able to
> download the file.
>
> How to make the directory / files only available to registered users
> using
> PHP code?
>
> (So that other users cannot download the file using direct url
> "http:\\www.abcd.org\downloaddir\setup.exe" )
>


I can give you the basics of this and hopefully someone can fill in
the gaps... What you need to do is put the actual file above the
webroot... and then set the include path to include that, then you
have your script go and fetch it.

Maybe this way makes more sense:
<HD>
<Web>
<Downloads>
<mydispatchscript.php>
<INC>
<setup.exe>
</HD>

so basically, in your php.ini file make sure you include the <INC>
directory and include the whole path to it. and you will be able to
access it but no one will be able to access the file directly.


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


--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424-9337
www.raoset.com
japruim@raoset.com



  Réponse avec citation
Vieux 07/04/2008, 17h25   #3
Daniel Brown
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] How to make a directory / file only available to registered users using PHP code?

On Mon, Apr 7, 2008 at 11:56 AM, Rian Hidayanto <rian.smart@gmail.com> 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!
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 10h12.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11951 seconds with 11 queries