help with this code...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

help with this code...

Post 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!!
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post 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; 
?>
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post 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
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post 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?
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post 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
Post Reply