Not sure if this is the right place for this, but I need to be able to run some PHP code before anything loads up on the server.
So far I have a .htaccess file with the following in it:
Code:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule (.*) auth.php?torun=$1 [QSA]
And in auth.php I have this:
PHP Code:
<?php
$method="http";
$domain="example.com";
error_reporting(E_ALL);
ini_set('display_errors', 1);
if ($_GET['grantaccess']=="true") {
$url=$method . '://' . $domain . '/' . $_GET['torun'];
unset($_GET['torun']);
unset($_GET['grantaccess']); //Comment out to prevent loop
if (count($_GET) >= 1) {
$queryString = "?" . http_build_query($_GET);
} else {
$queryString = "";
}
//header ( 'Location: ' . $url . $queryString);
printf ( 'Location: ' . $url . $queryString);
} else {
echo "Access denied";
}
So far it's working right up to the point where it runs header function. Once that's run there are 1 thing that goes wrong:
It re-executes the .htaccess file again (Which will cause an infinite loop if the "grantaccess" query string is put on). I basically want to somehow disable it re-executing the .htaccess file, or make it only run once per page load/connection.
Edit:
Fixed one of the problems myself, and updated the code.