Page 1 of 1

help with this code...

Posted: Mon Jan 12, 2004 9:32 pm
by Illusionist
Hey, for some reason theres a problem with this. What i'm doing is i have a few DDNS domains setup for my one IP address, and i made an index.php file that is always called from all the addresses, then it parses the header, and send them to the right directory...

I had it working with ASP, but decided to recode it in PHP, and it works, but only if i enter http://www. infront of it, if i jsut enter the address it wont work... but i think it should.. anyways....

Code: Select all

<?php
    $x=strtolower($_SERVER["HTTP_HOST"]);
    If(strpos($x,'this')>0)
        header("Location: /this");
    else if(strpos($x,'that')>0)
        header("Location: /that");
    else if(strpos($x,'what')>0)
        header("Location: /what");
    else echo "error! ".$x;
    ?>
I was just using >1, so i chaged it to >0 and it still wasn't working.
I've also tried ===true, but htat didn't work either...

Help Please!!

Posted: Mon Jan 12, 2004 10:08 pm
by microthick
Instead, you could try using strstr(). Code not tested, but might look like:

Code: Select all

<?php
$x=strtolower($_SERVER["HTTP_HOST"]); 
if (strstr($x,"this")) {
     header("Location: /this");
} else if (strstr($x,"that")) {
     header("Location: /that");
} else if (strstr($x,"what")) { 
     header("Location: /what");
} else echo "error! ".$x; 
?>

Posted: Tue Jan 13, 2004 6:03 am
by Illusionist
Hey, thansk for that code. I haven't tried it yet because i got it to work. I changed the > 0 to > = 0 and it works like a charm now!

Thanks

Posted: Tue Jan 13, 2004 11:06 am
by Illusionist
Oops! Actually i just tested the code i had before with just the first of my sites, i didn't try the other 2... The changes i made ( >= 0 ) don't work, and i know why... lol, so as soon as i get home, i'm going to try the code microthick posted above. I hope it works, and if it doesn't does anyone else know of anything i could do?

Posted: Tue Jan 13, 2004 10:12 pm
by Illusionist
Ok, i used teh strstr() and got it to work, but with the first two, if i don't put www. infront then i get an operation timed out error, but i dont when i add the www. infront... For the last one it doesn't do that...

This may or may not be a PHP problem, jsut wodnering if anyone knew why this is happening.

Thanks for the help microthick