WP plugin redirect for split test endless loop?

7 replies
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; 
#endless #plugin #redirect #split
  • Profile picture of the author johnnyN
    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?
    {{ DiscussionBoard.errors[4611538].message }}
    • Profile picture of the author jaybaker
      Nope... No frames no insertion twice... Heres the link to DL the file...

      http://www.bitsonline.us/wpfb/wp-con...split-test.php
      Signature

      Do you want to make successes or excuses? Success? Alright then... See what's in store for you....
      - The AC Assassin

      {{ DiscussionBoard.errors[4611588].message }}
      • Profile picture of the author Tim Brownlaw
        Hey Jay,

        What's going on, is that your redirect is being Hit each and every time the page is refreshed!.

        Remember that all Active WP Plugins are run each time a page is accessed.

        So your little plugin is sitting there merrily redirecting your pages in an endless loop.

        It has no idea that a certain IP address has already visited.
        So you need to make it show the 1st selected page and stop.

        You also want to log how many times domain X was displayed.
        So you could also log the IP address and check against it and maybe have a time for that IP to remain valid so if they come back at some stage they see the other page..... Depends on what you want it to do.

        The problem then is, if you do have other links accessible on the site, your plugin could throw them back to either of the 2 URLS you've configured.

        So that's the why... The "how to fix it" will have to be for another time., unless that gives you enough to tackle it.

        Without knowing what other code you have wrapped around this, it's hard to tell!

        It's all fun.

        Cheers
        Tim
        {{ DiscussionBoard.errors[4612931].message }}
      • Profile picture of the author jaybaker
        You can find the full plugin in the message below. I have even thrown out the header redirect and it is still redirecting between the two urls... Any suggestion on how to fix what you see happening is greatly appreciated.

        Jay

        Originally Posted by jaybaker View Post

        Nope... No frames no insertion twice... Heres the link to DL the file...

        http://www.bitsonline.us/wpfb/wp-con...split-test.php
        Signature

        Do you want to make successes or excuses? Success? Alright then... See what's in store for you....
        - The AC Assassin

        {{ DiscussionBoard.errors[4613179].message }}
  • Profile picture of the author jaybaker
    any idea how to fix this?
    Signature

    Do you want to make successes or excuses? Success? Alright then... See what's in store for you....
    - The AC Assassin

    {{ DiscussionBoard.errors[4615533].message }}
  • Profile picture of the author rufaswan
    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
    {{ DiscussionBoard.errors[4615890].message }}
  • Profile picture of the author Tim Brownlaw
    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
    {{ DiscussionBoard.errors[4616394].message }}

Trending Topics