views:

51

answers:

1

now i make simple system in my site and this its code

if(stc($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'])){
//download directly
}else{
//open page first
}
function stc($haystack, $needle, $offset=0) {
    return strpos(strtoupper($haystack), strtoupper($needle), $offset);
}

if any one enterd the link from my site its download directly ok and if from any other sites its open a page now its working great but if any one installed any downloader such as inernet download manager its make the link directly not going to page first i think because its make HTTP_REFERER null now how i can doing the system like rapidshare.com

+1  A: 

strpos can return 0.... 0 as in the pos a needle can be (at the first postion in the haystack, first position in a string is 0).

strpos() return's false if the needle was not found.

0 & false are both the same in if statements...

$test = 0; if (!$test) echo "0 is like false";

$test2 = false; if (!$test2) echo "This one is also false..";

You have to make sure it's false or 0, this you can do with: ===

if (strpos() === false)  echo "It's not found for sure!";

So your code becomes:

if(stc($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST']) !== false){
//download directly
}else{
//open page first
}
Frenck