How's my cloaking?

droplister

New member
Aug 23, 2007
1,233
21
0
NYC
I don't usually cloak or write scripts, so can someone look over this. It works well as far as I can tell, but can it be simplified?

It's both a split test(let me know if you know how to make it perfect 50/50) and fb cloak.

<?php
$tracking_ref = $_SERVER['HTTP_REFERER'];
$a=array( 'http://domain.com/metaredirect1', 'http://domain.com/metaredirect2');
if(strpos($tracking_ref,"intern")){
}elseif(strpos($tracking_ref,"facebook")){
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: " .$a[array_rand($a)]);
}
?>
I'm using a single meta refresh.

And in the event this is the best way to go about this have at it.
 


Works, right? Seems simple enough to me. No real need to make it 50/50; there are bigger things to worry about. Array_rand will work out in the long run.
 
keep in mind that strpos will simply tell you the position of the first occurrence of a match (which in php4 is the first occurrence of 'i' or 'f' since it won't work with a whole string like php5 will). But as a result if the first occurance is at the beginning of the string it will return zero which may be confused as false.

<?php
$t_ref = $_SERVER['HTTP_REFERER'];
$i_ref = strpos($t_ref, "intern");
$f_ref = strpos($t_ref, "facebook");
$a=array( 'http://domain.com/metaredirect1', 'http://domain.com/metaredirect2');

if(($iref === false)&&($f_ref !== false))
{
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: " .$a[array_rand($a)]);
}
?>

Since I'm basically assuming you're wanting to form a return only if it has facebook in the referer, but not if it has intern. (however that being said the above would be true if I put a folder called facebook on my own site and linked to it. Maybe preg_match if its important enough?)

Oh and the reason for === and !== is because if strpos returns zero meaning it found the match at the beginning of the string, === and !== won't consider a numeric value as false, but only a strict boolean.
 
  • Like
Reactions: droplister
Since I'm basically assuming you're wanting to form a return only if it has facebook in the referer, but not if it has intern. (however that being said the above would be true if I put a folder called facebook on my own site and linked to it. Maybe preg_match if its important enough?)
parse_URL may be useful here if you can't/don't want to use preg.
 
Question. I'm not a programmer, but could you use the stristr() function in place of strpos() in the above?
I have something like the following which *seems* to work as intended.
Code:
if (stristr($addy,'google') == TRUE) {
          do something;
    }
elseif(stristr($addy,'level3') == TRUE) {
          do something;
          }
 
Question. I'm not a programmer, but could you use the stristr() function in place of strpos() in the above?
I have something like the following which *seems* to work as intended.
Code:
if (stristr($addy,'google') == TRUE) {
          do something;
    }
elseif(stristr($addy,'level3') == TRUE) {
          do something;
          }

From PHP.net's manual regarding strstr

If you only want to determine if a particular needle occurs within haystack , use the faster and less memory intensive function strpos() instead.
 
Thanks kb I suck at making my if then statements compounded like that.

I don't expect people to be linking to these pages. I actually tested it would work by creating files intern.php, facebook.php, and facebookintern.php with links.
 
Thanks kb I suck at making my if then statements compounded like that.

I don't expect people to be linking to these pages. I actually tested it would work by creating files intern.php, facebook.php, and facebookintern.php with links.

And then there's the shit in my signature to do that on automation. :P

But speaking of compounding an if statement, bet this would have seemed confusing to you.

$target = ($iref === false)?"":$a[array_rand($a)];

basically condition?if-true:if-false; kinda like an iif() in other languages. But it can be handy if you're looking to fill something in-line as well.