Home > Technical & Creative Skills > Programming, Servers & Scripts

How to pass URL Parameters in .php redirect? (5)


04-25-2014 02:50 AM #1 zerosixty (Member)
How to pass URL Parameters in .php redirect?

I want to add tokens to my facebook ads. For example, keyword=woman

I am sending the ad to a site on my server with a .php redirect: www.mysite.com/redirect.php

This page has a php redirect script with my tracking link in it.

How do I go about setting this up so that my FB ad keyword parameter gets inserted into my tracking link on redirect and passes to my tracker?


04-25-2014 03:55 AM #2 zeno (Administrator)

This is very simple passing of querystrings. You use the $_GET['something'] function of PHP.

There is some example scripting for this in my FB tutorial - http://stmforum.com/forum/showthread...l=1#post147270 - definitely copy/paste the code into a syntax-highlighting program like Dreamweaver to make sense of it.

In short, to get the querystring data:

$_GET['keyword'];

So, you can use use $_GET['keyword'] in your affiliate link to insert "woman". You need to be careful with syntax and separating variables from static text. An example:

header('Location: http://myaffurl.com/something?a=1234&c=5678&s1='.$_GET['keyword'].'&s2=somethingelse');


04-26-2014 12:27 AM #3 zerosixty (Member)

argh i just tried it and couldn't get it to work.

<?php

header( 'Location: http://mytrackerlink.base.php?keyword='.$_GET['keyword'].'&ad=EDIT' ) ;

?>

At first I screwed up the syntax and the link didn't work. Now the link works but no parameter is getting passed to my tracker...


04-26-2014 12:53 AM #4 snipe (Member)

Make sure the URL is being built correctly.

You should be encoding the keyword so the URL doesn't break on special chars/spaces.

Code:
<?php

$kw=urlencode($_GET['keyword']);
$buildurl= "http://mytrackerlink.base.php?keyword=$kw&ad=EDIT";

echo "Build URL: $buildurl";
// header( 'Location: '.$buildurl);

?>
When you check the URL is being built correctly, uncomment the header line and comment out/remove the echo.


04-26-2014 01:11 AM #5 zerosixty (Member)

Thanks a lot I got it working!


Home > Technical & Creative Skills > Programming, Servers & Scripts