Percent chance to redirect to different pages

5 replies
Hey guys,

I need a bit of PHP code and I would be grateful if someone could help me.

Basically, the visitor will land on the page (with the code) and have a 30% chance to be redirected to page A and a 70% change to be redirected to page B..

Much appreciated

Jared
#chance #pages #percent #redirect
  • Profile picture of the author Bill Cook
    I guess the warrior forum won't let me use real varibles, but the code below should do it, as long as the headers haven't already gone out when this fires. (remove the space between the $ and myrand)

    Bill
    Code:
    $ myrand=rand(0,100);
    if ( < 30) {
    header('Location: http://www.example.com/pageA.html');
    }
    else{
    header('Location: http://www.example.com/pageB.html');
    }
    {{ DiscussionBoard.errors[4866409].message }}
    • Profile picture of the author timpears
      Originally Posted by Bill Cook View Post

      ...... as long as the headers haven't already gone out when this fires.
      What do you mean by this?
      Signature

      Tim Pears

      {{ DiscussionBoard.errors[4866811].message }}
  • Profile picture of the author breezynetworks
    Thanks so much, I will give it a try and update the thread asap
    {{ DiscussionBoard.errors[4866614].message }}
  • Profile picture of the author lordspace
    add this after the header

    Code:
    exit();
    By the way you should think about the *side* effects that this might have.
    The search engines don't like to be served different content.
    Just to keep that in mind.

    I guess you're doing some A/B testing but maybe you can list those landing pages in robots.txt file so search engines won't index it.

    Maybe SEO people should not more.

    Bill, that's brilliant!
    Signature

    Are you using WordPress? Have you tried qSandbox yet?

    {{ DiscussionBoard.errors[4869679].message }}
    • Profile picture of the author breezynetworks
      Originally Posted by lordspace View Post


      I guess you're doing some A/B testing but maybe you can list those landing pages in robots.txt file so search engines won't index it.

      Maybe SEO people should not more.

      Bill, that's brilliant!
      Great idea Thats for the additional code as well..
      {{ DiscussionBoard.errors[4869754].message }}

Trending Topics