WP plugin redirect for split test endless loop?

by 7 replies
9
Hello all,

I was looking for a plugin that can help with a split test for a product I am working on. However when I run this plugin it keeps going in an endless loop.

It sits there and switches between urls about every second or two and am not sure as to whats going on and what I can do to fix it.
If anyone can tell me whats going wrong I'd greatly appreciate it.

I am only going to post the main function of the code as the rest is rather irrelevant.

PHP Code:
        $domain1=get_option('domain1');
        
$domain2=get_option('domain2');
        
$ct 0;
 if(!empty(
$domain1) || $domain1 != null){
   
$ct=$ct+1;     
 }elseif(!empty(
$domain2) || $domain2 != null){
     
$ct=$ct+1;
}
$test rand(0,$ct);
if(
$test == 0){
    
$location $domain1;
}else{
    
$location $domain2;
}
header("Location: ".$_SERVER['HTTP_HOST'].$location);
exit; 
#programming #endless #plugin #redirect #split
  • i don't think the problem is in the code here. (all the code does is randomly choose one of the links)

    the problem is somewhere else. I would say the issue is in the code that is firing the code you pasted. could it be you use frames? or somehow have this code inserted twice?
    • [1] reply
  • any idea how to fix this?
  • I just saw your site, and I am surprise to see you add the the code (in javascript) again on the header and footer as well.

    The code you shown is PHP code. By counting, the server randomly choose a page once, then when loading it redirect again, and when it reach down to the footer, it redirect and read the whole page again. There is no end to this.

    You should use only one redirect. If you excluded the code from the plugin, did you put any redirecting code manually by yourself?

    - Rufas
    • [ 1 ] Thanks
  • Rufus picked up the problem you are seeing.

    You've got two javascript redirects merrily redirecting your site between the links you've got on WordPress For Beginners

    First thing to do is remove those and that nonsense will go away.

    Next: the link for the php is.
    1. Broken due to you having added a handler for register_activation_hook and not defining the function... Check the link you've given and see the error yourself.

    2. Giving us a link to your php file isn't going to let us actually see the code unless you create a copy and remove the php tags so it won't run and instead just show the code.

    In regards to the code you did provide... I went to the trouble of tossing that into a plugin and testing it on my test site. After having commented it to death, but for some reason the Forum wasn't wanting to play and let me show it, it did what I expected. It went into an endless loop.

    It has some other fundamental issues apart from the out of control redirecting.

    So if you can mod your file so it's viewable, then we can take a bit more of a look.

    This could turn out to be a nice little exercise in going from "what the...." to finding out what the problem is, and possibly fixing it.

    Cheers
    Tim
    • [ 1 ] Thanks

Next Topics on Trending Feed