Shortening/Masking URL with PHP

Discussion in 'PHP' started by Pentarix, Apr 13, 2006.

  1. #1
    I'm interested in masking and shortening some URL's on my site, which is a wordpress blog.

    So far I've come across this method here: http://www.stevedawson.com/article0006.php
    and the code looks like this:
    <?PHP
    /*
    Save this page as jump.php and when linking to this script use the following:
        <a href="jump.php?m=XXXXXX">XXXXXX</a> 
    Where XXXXXX is your merchant. 
    */
    if ($m == "") {$link = "http://www.stevedawson.com/mobiles/";} // Default Blank
    if ($m == "Just Phones") {$link = "http://www.awin1.com/awclick.php?mid=97&id=38362";}
    if ($m == "UKPhoneShop") {$link = "http://tracker.tradedoubler.com/click?p=985&a=949731&g=5119";}
    
    /*
    To add more jump links, just copy and paste one of
    the lines above and modify the $m and $link values
    */
    
    header("Location: $link"); // Jump to the hiddden affiliate URL above
    exit();
    ?>
    PHP:
    Now this works somewhat, but will bounce me back to my website URL that I've listed properly in the code, and it won't actually take me to the intended URL, (ex. http://www.awin1.com/awclick.php?mid=97&id=38362). I even tried it with the default settings, with the file the writer of this code (in the url above) provided, but I get the same result. Instead of being directed to any link, I get bounced back to his website (http://www.stevedawson.com/mobiles/).

    I've been searching online and this is the only way I've come across to mask a URL (besides tinyurl, which I don't want). Can someone please tell me what is wrong with this method and way it is being executed, or another way to do it altogether? Thanks.
     
    Pentarix, Apr 13, 2006 IP
  2. onlyican.com

    onlyican.com Peon

    Messages:
    206
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Mod Rewrite

    create a file called .htaccess

    Then add in there

    Options +FollowSymLinks
    RewriteEngine On

    RewriteRule ^x y [L]

    x being the url you want them to see
    y being the real url

    for example
    http://www.awin1.com/awclick.php?mid=97&id=38362
    RewriteRule ^awclick/$1/$2 awclick.php?mid=$1&id=$2[L]

    This will show
    awclick/97/38362
     
    onlyican.com, Apr 13, 2006 IP
  3. Pentarix

    Pentarix Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    When I did that, it made my webpage give a 500 error and was inaccessible through the browser. Any idea why or other suggestions?
     
    Pentarix, Apr 13, 2006 IP
  4. onlyican.com

    onlyican.com Peon

    Messages:
    206
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You did not set the .htaccess correctly
     
    onlyican.com, Apr 13, 2006 IP
  5. Pentarix

    Pentarix Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I'm sorry, I have no idea what that means.
     
    Pentarix, Apr 13, 2006 IP
  6. inerte

    inerte Peon

    Messages:
    78
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Try $_GET['m'] instead of $m. Perhaps your webhost has register_globals off (the way it should be)
     
    inerte, Apr 13, 2006 IP
  7. Pentarix

    Pentarix Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    That did it, thanks inerte!!
     
    Pentarix, Apr 14, 2006 IP
  8. smiNICOLETTE

    smiNICOLETTE Peon

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    thanks for this coding. it works awesome.
     
    smiNICOLETTE, Dec 17, 2006 IP