Redirect with variable entered into redirect url

just-buyin-stuff

Registered Member
Joined
Jun 30, 2013
Messages
94
Reaction score
48
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.
 
something like this...

Code:
$newString = "blabla" . $variable . "blabla";
header("Location: /whatever?param=$newString");
 
cant you just create a cname?

edit.. never mind.. I overlooked "variable"
 
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.

Example URL: http://firstsite.com/index.php?referrer=timtebow
<?php echo "<a href='http://secondsite.com/".$_SERVER['QUERY_STRING']."'>click here bitches!</a>"; ?>
Which when followed,will take you to:
http://secondsite.com/referrer=timtebow

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.
 
Last edited:
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.
 
Make sure you put an exit; after your header redirect. You might also want to put your redirects inside your .htaccess
 
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
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!
 
Back
Top