I got this rotating redirect code php

by vjboc
5 replies
I got this rotating redirect code php. You can have as many addresses as you want. Just ad another $aff[] = 'Put url here'; to the list. Is there a way to add google analytics on the same page as this code? I know I can put google analytics on the redirected pages. Can it be put on the same page as this code and work?

<?php
$k = $_GET['sub'];

$aff[] = 'Put url here';
$aff[] = 'Put url here';
$aff[] = 'Put url here';
$aff[] = 'Put url here';
$aff[] = 'Put url here';
$aff[] = 'Put url here';

srand ((double) microtime() * 1000000);
$random_number = rand(0,count($aff)-1);

$lol = ($aff[$random_number]);
$lal = $lol.$k;

header("Location: $lal"); ?>
#code #php #redirect #rotating
  • Profile picture of the author vjboc
    Can anyone help with this?
    {{ DiscussionBoard.errors[6770767].message }}
  • Profile picture of the author Lovelogic
    <?php
    $k = $_GET['sub'];

    $aff[0] = 'Put url here';
    $aff[1] = 'Put url here';
    $aff[2] = 'Put url here';
    $aff[3] = 'Put url here';
    $aff[4] = 'Put url here';
    $aff[5] = 'Put url here';

    srand ((double) microtime() * 1000000);
    $random_number = rand(0,count($aff)-1);

    $lol = ($aff[$random_number]);
    $lal = $lol.$k;

    header("Location: $lal"); ?>

    All about PHP array ---> PHP Arrays

    No you cannot put analytics on a page redirecting usig PHP.
    Analytics uses Javascript that runs inside the clients web browser,
    this redirect uses PHP on your webserver. The visitor never sees
    anything that happens on this page only the redirect.
    {{ DiscussionBoard.errors[6773087].message }}
  • Profile picture of the author vjboc
    Is there other ways of rotating redirects that can be used with analytics?
    {{ DiscussionBoard.errors[6775930].message }}
  • Profile picture of the author tweakr
    In short, no you can't have analytics on this page. It wouldn't record any traffic.
    It is possible, but you would have to build your own stats tracking script; "off the shelf" analytics like google or piwik wouldn't do it without breaking the redirect.
    {{ DiscussionBoard.errors[6796562].message }}
  • Profile picture of the author Big Squid
    tweakr is correct...this page will never hit the browser. The only thing that will get returned is the header redirect.

    You could record hits on this page, by using something like:
    INSERT INTO [the tracking db] (link, time) VALUES ('$lal, NOW())
    {{ DiscussionBoard.errors[6860656].message }}

Trending Topics