You might want to first try just echoing Attempting to Redirect
in place of the header, so you can then see if it is trying to redirect someone. That way you can check if the first half of the function works.
Here is a blog post about something very similar to what you are doing, that uses strpos instead of preg_match, which is probably more straightforward.
If it isn't 'redirecting', AKA, the header
function doesn't appear to be working, you have a whole other problem.
If the header
function isn't working, try adding Firefox to the list of browsers to redirect, and then use Firebug to check the headers being sent to the browser.
The might be a problem with how PHP and Apache are interacting.
There is a chance that you have error_reporting turned off. If you do, PHP might be trying to output an error that says there is whitespace sent out before your header command.
Before the header()
command, trying setting error_reporting(E_ALL);
, and check if it gives an error messages to the avail of
Headers could not be sent. Headers have already been sent on file.php line 1.
Basically, if you send any HTML, Whitespace, or pretty much any sort of output before the header()
command, PHP will error as headers must be sent before the content of the page. After the first whitespace is sent, headers are sent, and you can't send anymore
You can check if headers are sent using header_sent()
if(headers_sent()){ echo "Headers Sent"; }