Htaccess Login and Password

Asked

Viewed 369 times

2

I’m having a problem, I have a directory of different files type csv, xls, pdf, docx... I wanted that person. h that put in the browser the file link did not have access to it, only those who made the access by the login page had access. How do I do that?

1 answer

0


To do this, you will create an authentication system (much like login system).

Ex Basico:

<?php

if($_GET['url'] == 'arquivo'){
   if(!$_SESSION['login']['auth']){
       echo '<input type="text" name="email"><input type="password" name="senha">';
   }
}

The initial logic is this, but you have to evolve into something more complex, use Hash and etc.

.htaccess

<Directory /caminho> 
    Options -Indexes 
</Directory>
  • But how do I block access to the files?

  • I already have the login page that way

  • You will block direct access to the files via URL, this way will display the files using PHP. I will update the code, showing how to block with htaccess

  • Okay, I already know this, but it doesn’t solve the problem, for example: localhost/files/.pdf file, whoever types this has access to the file. But I wanted only those who have the access session to have access to it

Browser other questions tagged

You are not signed in. Login or sign up in order to post.