6 replies
Anyone have a php redirect script for multiple URLs, that doesn't select the URL randomly?

thanks
#php #redirect
  • Profile picture of the author mywebwork
    Hi Ryan

    Perhaps it's because I've been at it all day and I'm tired, but I don't quite understand what you are asking for. Could you clarify it for an old guy like me? I might be able to assist you.



    Bill
    {{ DiscussionBoard.errors[1677509].message }}
  • Profile picture of the author chaos69
    Originally Posted by Ryan_Taylor View Post

    Anyone have a php redirect script for multiple URLs, that doesn't select the URL randomly?

    thanks
    Do you mean something like this?

    <?php
    $urls=array();
    # The exitvar below is where you redict people too. For example, in
    # in this case it would be out.php?ex=SITENUM. If you change the
    # value to be "site" then it will be out.php?site=SITENUM


    # (Where SITENUM is from the list below .....

    $exitvar = "ex"; # Change this if needed.

    # SITENUMS
    # You must set the first line below to be your home page
    # This is the default and is also out.php?ex=0

    $urls[]="http://www.YOURWEBSITE.com"; # HOME PAGE (0)

    # In order to add new URLS simply add a new line as above but include
    # the url to redirect too.... The first entry here will be out.php?ex=1
    # and then count up from there.


    # This would be http://www.YOURWEBSITE.com/out.php?ex=1
    $urls[]="http://YOURFIRST.AFFILIATELINK.COM"; # (1)

    # This would be http://www.YOURWEBSITE.com/out.php?ex=2
    $urls[]="http://YOURSECOND.AFFILIATELINK.COM"; # (2)

    if(sizeof($urls) == 0 || !is_array($urls))
    header("location:http://".$_SERVER['HTTP_HOST']);
    elseif(!isset($_GET[$exitvar]) || $_GET[$exitvar] == '' || $_GET[$exitvar]=='0')
    header("location:".$urls[0]);
    else
    {
    if(!array_key_exists($_GET[$exitvar], $urls))
    header("location:".$urls[0]);
    else
    header("location:".$urls[$_GET[$exitvar]]);
    }
    ?>


    This was quickly thrown together - you might want to add extra error checking in there and such.

    Bascially, add your URLs and then to redirect just call it as;

    http://www.yoursite.com/out.php?ex=X

    Where;
    out.php = the filename of the script
    ex = the value you enter in $exitvar
    X = the number of the affiliate link.

    You might want to actually use an associative array so you can refernce it as ?ex=affiliatesite but you will have to change the code slightly to work it in.
    Signature
    Best Ways To Make Money Online

    Eight bytes walk into a bar. The bartender asks, “Can I get you anything?”
    “Yeah,” reply the bytes. “Make us a double.”
    {{ DiscussionBoard.errors[1678254].message }}
  • Profile picture of the author HomeBizNizz
    Originally Posted by Ryan_Taylor View Post

    Anyone have a php redirect script for multiple URLs, that doesn't select the URL randomly?

    thanks
    You can easily use something like this:
    PHP Switch Statement
    PHP: switch - Manual

    I have it then redirecting links from my ebooks.
    {{ DiscussionBoard.errors[1682849].message }}
  • Profile picture of the author webknight1
    While I realize this is an older post, I'm surprised it hasn't been more active.

    When you get right down to it, I was having the same issues finding a script that did what I wanted it to do. So I wrote one! A nice and simple little script that will do a simple redirect WHERE you want it to go, or a random redirect depending on the traffic you are sending through it.

    If this sounds like something you may be interested please feel free to PM me.
    Later!
    {{ DiscussionBoard.errors[1907048].message }}
  • Profile picture of the author alf82
    <?php
    header( 'Location: http://YOUR AFFILIATE ID/?' ) ;?>

    This is a standard php redirect without tracking code. - not really sure what you want. I do every link separately. It sounds like you bought a crappy randomizer - why I do not know. Loseweight-keepfit.com
    {{ DiscussionBoard.errors[1915466].message }}
  • Profile picture of the author Damien Roche
    You can do something very simple like so:
    class myRedirects{

    function Redirect($id){

    header("Location:".$this->redirects[$id]);

    }

    }

    USE:
    $myRedirect = new myRedirects();

    $myRedirect->redirects['redirectid1'] = 'http://somedomain.com';
    $myRedirect->redirects['anyidyouwant'] = 'http://somedomain2.com';

    $myRedirect->Redirect('redirect1');
    So you can register as many redirects as you like and then use the redirect by simply using that:
    $myRedirect->Redirect('redirectid1');
    ..of course, you can just use:
    header("Location:http://somedomain.com");
    ..but the above allows you to manage your redirects better. You could then randomize, affix other parameters (random if you like), store and retrieve in database etc. etc.

    Hope that helps.
    Signature
    >> Seasoned Web Developer (CSS, JavaScript, PHP, Ruby) <<
    Available for Fixed Fee Projects and Hourly ($40/hr)
    {{ DiscussionBoard.errors[1915974].message }}

Trending Topics