1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Redirect with variable entered into redirect url

Discussion in 'PHP & Perl' started by just-buyin-stuff, Dec 16, 2013.

  1. just-buyin-stuff

    just-buyin-stuff Registered Member

    Joined:
    Jun 30, 2013
    Messages:
    92
    Likes Received:
    41
    Php is something I know pretty much nothing about so I'm hoping someone can point me in the right direction. This may be something simple but my searches on google didn't turn up what I'm looking for. My guess I just don't know what to search for.

    What I'm looking to do is redirect from abc.cm/variable to cba.cm/blahblah"insert variable here"blahblah. So abc.cm/dogs would redirect to cba.cm/blahblahdogsblahblah.

    This would keep me from needing to create 1000s of redirects manually.
     
  2. bartosimpsonio

    bartosimpsonio Jr. VIP Jr. VIP Premium Member

    Joined:
    Mar 21, 2013
    Messages:
    7,477
    Likes Received:
    6,611
    Occupation:
    Webdev
    Location:
    27B-6
    something like this...

    Code:
    $newString = "blabla" . $variable . "blabla";
    header("Location: /whatever?param=$newString");
    
     
    • Thanks Thanks x 1
  3. CosmicSoundz

    CosmicSoundz BANNED BANNED

    Joined:
    Apr 30, 2012
    Messages:
    1,230
    Likes Received:
    1,295
    cant you just create a cname?

    edit.. never mind.. I overlooked "variable"
     
  4. Hecate

    Hecate Registered Member

    Joined:
    Jul 22, 2013
    Messages:
    50
    Likes Received:
    13
    PHP can be a bit tricky, in that there are always multiple ways to do the same thing. Are you wanting to capture the entire URL, or just looking to pull out the GET variables with values? The easiest way, is just to make use of $_SERVER['QUERY_STRING']. It will give you everything posted after the domain and page, which includes all variables, values, and extraneous characters. However, if you aren't expecting to have anything more than 1 or 2 variables, then this should work out fine.

    Before I forget, let me just say that allowing any form of unsanitized user input to be executed or otherwise carried out is a general no-no in programming. Something like this wouldn't result in a vulnerability any more dangerous than Cross Site Scripting, which can't be used for much else than social engineering... but just be wary of how this is implemented! No passing user credentials, or dates to secret meetings ;) haha. Best of luck friend! And shoot me a message if you end up needing more help on this.
     
    • Thanks Thanks x 1
    Last edited: Dec 16, 2013
  5. just-buyin-stuff

    just-buyin-stuff Registered Member

    Joined:
    Jun 30, 2013
    Messages:
    92
    Likes Received:
    41
    Code:
    <?php echo  
    
    header("Location: hxxp://secondsite.cm/".$_SERVER['QUERY_STRING']."");?>
    That seems to be working like I was hoping for. I figured it was so simple it was stupid for anyone that knew php at all. Thanks guys.

    Incase anyone is wondering what this is for it's for sending traffic directly to the item shown without showing my affiliate link.
    So instead of amazon.cm/linkcodeobviouslytryingtomakemoney/dogchewtoy/idcode=12345

    I can post a link to mysite.cm/?dogchewtoy someplace and they get redirected to the amazon link code with the product name entered in it. I'm not really using amazon btw it's just an example. All the links will be on my site so no I'm not planning on spamming fb or anything lol. This is just a huge time saver so I don't have to make a ton of redirects by hand.
     
  6. abda53

    abda53 Newbie

    Joined:
    May 14, 2010
    Messages:
    11
    Likes Received:
    1
    Make sure you put an exit; after your header redirect. You might also want to put your redirects inside your .htaccess
     
  7. funque

    funque Newbie

    Joined:
    Dec 27, 2013
    Messages:
    21
    Likes Received:
    1
    It depends of your partner website - when you send traffic to affiliate link, website can set cookie and forward user to clean URL without affiliate ID. You can't change these things - sorry!