Question

Basically, I am trying to make a split-test web app, and I'm a bit confused on how to do this without any race conditions.

Basically, there are 3 pages:

  • main_page.php
  • page1.php
  • page1_alt.php

So the process is as follows:

  1. user visits main_page.php
  2. main_page.php checks for a cookie

    • a. if there is no cookie create a cookie,
    • b. check the page the last visitor was sent to
    • c. send the current visitor to the other page (if last visitor went to page1.php, send this one to page1_alt.php)

I have the cookie issue sorted out, I just want to know what you think is the best method on how to do step 2b. If i write to the db, it would be impractical. If I refer to a text file, it would produce possible race conditions.

EDIT: If you think there's an easier way than starting from scratch, do give me some suggestions.:)

Was it helpful?

Solution

I'm not sure I completely understand why you want to do this, or why writing to the DB would be impractical. If you want to split them with exact precision, this seems to me to be the best possible solution.

If however you just need to split them approximately without DB-access, you could be creative:

if (date('s') % 2 == 1) {
  header("Location: page1.php");
} else {
  header("Location: page1_alt.php");
}

Of course there is some chance involved in this, but since seconds are equally distributed, if you have enough users, the two groups should be quite close to equal size.

OTHER TIPS

I know google analytic can do split testing, I'm not sure what your end goal is but with GA It will split the users and test which page get's the user to the goal the most. Sorry if this wasn't what you were looking for.

Consider using sessions instead of cookies. Sessions are more flexible and secure way to track user activities.

You should be using sessions and header("Location:...);. From that you can do something like this

    if (!isset($_SESSION["var"])) {
    header("Location: main_page.php");
}

Where $_SESSION["cookie"] is whatever you want to set it to be. I guess in your case you could set to what page they were at last. Then you can just check if it exists and/or what it is and use header to send them to the appropriate page.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top