.htaccess - How to restrict access to directory on server, using PHP logic? -
i have directory on server want general public not have access to. (nothing. no access php files, images, anything.)
but want allow users access restricted area based on boolean value in php.
is there way use php determine whether or not user can access directory, similar using htaccess file more customized logic?
one of easiest way redirect restricted users homepage.
<?php header( 'location: http://www.yoursite.com' ) ; exit; ?>
you can allow access specific users setting boolean value in db.
below solution work based on file storage location.
$file = '/file.png'; // set file location $useraccess = false; if (file_exists($file) && $useraccess) { header('content-description: file transfer'); header('content-type: application/octet-stream'); header('content-disposition: attachment; filename=your_file.png'); header('content-transfer-encoding: binary'); header('expires: 0'); header('cache-control: must-revalidate'); header('pragma: public'); header('content-length: ' . filesize($file)); ob_clean(); flush(); readfile($file); }
check link also.
hope :)
Comments
Post a Comment