[HELP] PHP scripts for redirecting purpose

by 17 replies
20
Hi

I want to send visitors to 5 different squeeze pages using some kind of php redirect.

This means that when Visitor A come via URL, automatically he will be redirected to URL1 and the next visitor will be re-directed to URL1.

So, Visitors Click on the link and sequentially each will be directed to different squeeze pages.

Let say I have 5 visitors who click through the link, so:

visitor 1 -> URL1,
visitor 2 -> URL2,
visitor 3 -> URL3,
visitor 4 -> URL4,
visitor 5 -> URL5,
visitor 6 -> URL1,

and so on....

Can someone teach me how to do this using PHP re-direct? Thanks...
#programming #php #purpose #redirecting #scripts
  • Ok this should work

    <?php

    $links = array("URL1", "URL2", "URL3", "URL4", "URL5");

    $hits = @file_get_contents("hits.txt");

    $fh = fopen("hits.txt", "w");

    if($hits >= count($links))
    {
    $hits = 0;
    fputs($fh, $hits);
    }
    else
    {
    $newhit = $hits + 1;
    fputs($fh, $newhit);
    }

    fclose($fh);

    header("Location: ".$links[$hits]);

    ?>
    • [1] reply
    • When I did the above, re-direction did not take place, and the browser showed:

      = count($links)) { $hits = 0; fputs($fh, $hits); } else { $newhit = $hits + 1; fputs($fh, $newhit); } fclose($fh); header("Location: ".$links[$hits]); ?>

      Not sure why it didn't work. :confused:

      My questions:

      Do I have to create a dummy file hit.txt and upload to same directory?
      Am I suppose to replace the URL1, URL2, URL3, URL4, URL5 with where I want to redirect to and keep everything else intact?

      Thanks to advise.
  • if you want redirect to different page
    <?php
    header("Location:your address here");
    ?>
    you can do this random with PHP RAND (google it)
    do something like this
    PHP Code:
    <?php
    =rand(1,5);
    if(==
    1){
    =
    "your address";
    }
    if(==
    2){
    =
    "another address";
    }
    //you need to continue ...
    echo "<a href="">click here</a>";
    ?>
    good luck!!!
    • [1] reply
    • Sorry, I'm a little slow. Don't really understand what you mean. Am not a techie at all.. :p Can you make it idiot proof, please?
  • Heh there seems to be problems with warrior forum php insertion compare this code with my edited post and youll see difference. Grab edited code from my first post and it should work.

    hits.txt will be generated automatically
    and yes replace UR1, URL2 and so on with your desired links. You can add them as much as you wish
    • [1] reply
    • @kaido

      Thanks for reply. Still having the same problem. :confused:

      No redirection happen. Only the following is displayed in the browser:

      = count($links)) { $hits = 0; fputs($fh, $hits); } else { $newhit = $hits + 1; fputs($fh, $newhit); } fclose($fh); header("Location: ".$links[$hits]); ?>
      • [1] reply
  • Its php file so if you will rename it to "redirect"
    then you should access it as http://www.mydomain.com/redirect.php
    • [ 1 ] Thanks
    • [1] reply
    • @Kaido,

      Oops! :p Sorry. I'm dumb. Let me try it with the file you have provide. I really appreciate your kind help. Have been trying to solve this for 4 days now
      • [1] reply
  • Are you trying to do a split test? If so why don't you just use Google Website Optimizer to do your split testing for you? It's easier and it works better with Google Analytics.
    • [ 1 ] Thanks
  • Ok i made an script for you for easier managment.
    https://rapidshare.com/files/459979661/redir.zip

    Basically you can add and remove websites from it by logging in from admin/index.php
    username as "user" and password is "pass" you can change them from conf/config.php
    also it displays how many hits specific link has got.

    Happy redirecting
    • [ 1 ] Thanks
    • [1] reply
    • AWESOME! Thanks Kaido. You are SUCH a great help - honestly. Let me try out the new solution and give you some feedback. I'm really lost without a solution. If I can put another few thanks under your belt, I would. For now let me get you a drink of your choice => cU

      Yes, I'm trying to split test the opt in pages. The original plan was to use Google Website Optimizer, and I tried getting it to work. However, for some reason, I can't get the scripts into the <head></head>. Tried several plugins including HiFi and GWO4WP. None work. It could be the theme I'm using. I'm on multi stream theme. Would be glad if you can teach me how to make it work... :p
      • [1] reply
  • No problem

Next Topics on Trending Feed