php - Making a downloadable file password protected on webpage -


i want make webpage has download option pdf, want password protected i.e. if clicks on link has enter username , password , if directly open link "www.example.com/~folder_name/abc.pdf" server ask password first , allow download

edit: want user view file in browser, not force download here code

<?php     /* authentication script goes here*/     $file = 'http://example.com/folder_name/abc.pdf';      //header('content-description: file transfer');     header('content-type: application/pdf');     header('content-disposition: inline; filename=' . basename($file));     header('content-transfer-encoding: binary');     //header('expires: 0');     //header('cache-control: must-revalidate, post-check=0, pre-check=0');     //header('pragma: public');     header('content-length: ' . filesize($file));     header('accept-ranges: bytes');     @readfile($file);  ?> 

but code not opening pdf in browser. don't want code depend upon pdf plugin used browser

you can make .htaccess file in web folder have download set @ before can enter domain, have enter correct user , password in.

here's blog post used when set own .htaccess file this:

authtype basic authname "restricted area" authuserfile /path/to/file/directory-you-want-to-protect/.htpasswd require valid-user 

you need create .htpasswd file can put username , password. password needs encrypted md5 hash can use generator links in blog. hope helps.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -