Rotating code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • LeeUK
    New Member
    • Nov 2006
    • 1

    #1

    Rotating code

    I have a site that I run with 2 other people & we each have a google adsense account to help pay for the site. I want to be able to rotate our codes so that each of our ads appear evenly.

    I have made a constants.php page & put the three codes as constants like this
    Code:
    define (USER1, '<script>a bunch of code here</script>');
    define (USER2, '<script>a bunch of code here</script>');
    define (USER2, '<script>a bunch of code here</script>');
    Then I have called for constants.php in all pages, and I am manually rotating them every other day.
    Is there a piece of code that I can enter on the main pages that will auto rotate them? or is it a little more complicated & I should get a programmer?

    Thanks.
  • TheMadMidget
    New Member
    • Oct 2006
    • 98

    #2
    This will rotate on each visit. Make sure you have the "hits.txt" file writtable. This is based off a counter and will still give you a counter, but hidden.
    To add or remove user/accounts, just change the $numberOfAccoun ts and make or delete another "case:" structure.
    [PHP]
    $hitslog = "hits.txt"; # Path to the hits file, leave alone if in the same directory
    $hits = file($hitslog);
    $hits = $hits[0] + 1;

    ## Opening the hits file and write the number of hits:
    $fp = fopen($hitslog, "w");
    fwrite($fp, $hits);
    $numberOfAccoun ts = 3;
    $account = ($hits % $numberOfAccoun ts) + 1;

    switch ($account) {
    case 1:
    echo "<script>Us er1</script>";
    break;
    case 2:
    echo "<script>Us er2</script>";
    break;
    case 3:
    echo "<script>Us er3</script>";
    break;
    }
    [/PHP]

    Comment

    Working...