Not_Lazy Not_Lazy - 1 year ago 68
PHP Question

PHP redirection based on DNS

say i have a file named redirections.txt that looks like this:


how would i go about processing that text document as
domain-prefix: redirect-url
? (or "if $_SERVER['HTTP_HOST'] equals, goto redirect-url")

currently i have:

$file = file('redirections.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach($file as $line => $cont){
preg_match('/(*.?): http:\/\/\/(*.?)\//', $cont, $matches);
print_r($matches); // Debug. Was trying to see if it worked.

Answer Source

You can use explode() to split the line:

$split = explode(': ', $cont);
if (count($split) == 2) {
    list ($domain_prefix, $redirect_url) = $split;
    if ($_SERVER['HTTP_HOST'] == "$") {
        header("Location: $redirect_url");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download