I want to assign a variable from within PHP and make said variable available to my .htaccess
file so that it can use the value to, for example, deny or allow access.
Example index.php
file:
<?php
session_start();
$_SESSION['REMOTE_USER'] = 'valid';
$_SERVER['REMOTE_USER'] = 'valid';
$_ENV['REMOTE_USER'] = 'valid';
putenv('REMOTE_USER=valid');
print 'You are allowed.';
Here is one example of what I've tried inside the .htaccess
file (which is in the same directory as index.php
):
# Doesn't work... Always denied.
SetEnvIf Remote_User valid allowed
SetEnvIf Remote_User notvalid disallowed
Deny from all
Allow from env=allowed
Is there a way to allow or deny access through .htaccess
based on values provided by PHP?