Passing variables in redirect

9 replies
Howdy folks!

I won't bore you here with the details of why I want to do this, but can anyone please tell me how?

MyClickTracker-AffLink ----to----> clicktracker (which appends a location-based tracking ID, e.g. ?tid=sidebar) ----to----> php-redirect, which picks up the TID in the link before finally redirecting to the vendor page.

*phew!*

An example might be:

satellitesite01.com/linktracker/juicyapples

----to---->

[link-tracking program, which is set to the following link with variable]

mainsite.com/growingapplesebook.php?tid=sidebar

----to---->

[growingapplesebook.php is, itself, a standard php header redirect which contains myAffID and picks up the tid]

vendorpage.com&hop=myaffID&tid=sidebar

--------------------------------

I've tried using [GET] and [REQUEST] functions like this in the "growingapplesebook.php" file:

[[php
header( 'Location: hxxp://mylinkhere.com/?[[php echo $_REQUEST["tid"]; ]]' ) ;
]]

...and...

[[php
header( 'Location: hxxp://mylinkhere.com/?[[php echo $_GET["tid"]; ]]' ) ;
]]

But neither are picking up the "tid" variable, i.e. "sidebar" in this example.

If anyone can help me out with this, I'd be GREATLY appreciative!

Thanks very much ,
TheNightOwl

=============================


P.S. And in the event that you are interested as to why...

I want to be able to track which locations/links/banners/etc are leading to conversions by placing a tid linked to each location (e.g. sidebar, banner01, textlink, etc.)

But... I don't want to create fifty thousand links in my link-tracker (with location tids on every link) and then have to go back in and change them all if I want to change the CB affiliate nick.

Instead, I want to be able to point ALL links for Product-A to product-A.php (redirect) and get that redirect to "grab" whichever location TID I append to it in the link-tracker (e.g. product-A.php?tid=sidebar, product-A.php?tid=banner01, etc..

Does that make sense at all? (I have a feeling I'm overcomplicating it! LOL! )
#passing #redirect #variables
  • Profile picture of the author KirkMcD
    mylinkhere.com/?[[php echo $_GET["tid"]; ]]' )
    You're not setting the variable, just passing it.

    Do this:
    header( 'Location: hxxp://mylinkhere.com/?tid='. echo $_GET["tid"] ) ;
    {{ DiscussionBoard.errors[2444724].message }}
  • Profile picture of the author TheNightOwl
    Heya, Kirk

    Thanks very much for taking a punt. (Thanks, also, to Jeff, who PMed me).

    No joy, though, I'm afraid. This is what I get...

    Parse error: syntax error, unexpected T_ECHO in /home/filepathhere/growingbigjuicyapplesebook.php on line 2



    P.S.
    Thanks for highlighting the missing tid= by the way. In my head I realised I would only be pulling the value of tid, but I missed a step in the execution. I may have gotten it to work and then not got any actual reporting from the affiliate network anyway. Doh!
    Signature
    {{ DiscussionBoard.errors[2445761].message }}
  • Profile picture of the author SteveJohnson
    What's with all the "echo"s?

    The simplest is to do this:

    header( 'Location: hxxp://mylinkhere.com/?tid=' . $_GET["tid"] );

    However...raw user input should never be used. If you know exactly what form the tid should be, you can sanitize the input. At the bare minimum, use stripslashes:


    $tid = stripslashes( $_GET['tid'] );
    header( 'Location: hxxp://mylinkhere.com?tid=' . $tid );
    Signature

    The 2nd Amendment, 1789 - The Original Homeland Security.

    Gun control means never having to say, "I missed you."

    {{ DiscussionBoard.errors[2445863].message }}
  • Profile picture of the author TheNightOwl
    Thank you very much, Steve!

    Jeff sent me the very same code via PM so thanks again to him, too. Being a dumb-arse, I didn't think it worked because the tid didn't show up on the vendor page along with the hop (I'm testing this with some CB products). Of course, it does get passed ("invisibly") and a look in my reports today shows that to be true.

    So thanks again.

    Jeff also mentioned sanitizing further. I'm a total novice re: php so I didn't really know what that meant.

    I've done a little research and I understand a bit better now. I also went over the w3schools and found the various filtering functions.

    My variables are just letter/number combinations such as "sidebar," "banner01," "404page." etc.

    I couldn't see any of the sanitizing functions that would remove everything except letters and numbers. (And I wouldn't have the faintest idea how to actually use that code anyway! I read this tutorial, but don't really understand it, to be honest.)

    I understand the basic idea that if I don't sanitize it, then someone could come along, append some nasty string to the end of the URL and do bad stuff (the likes of which I have no idea; "bad stuff" is enough for me to understand that I'd want to avoid it, if possible! )...

    My situation is that I'm going from [link on my affiliate page] to [link-tracker/redirect] to [redirect that picks up the tid].

    Someone would have to know the URL of that redirect picking up the tid to do any damage, wouldn't they?

    And that's not publically available because it's inside my link-tracking software. If they appended something nasty to the affiliate link, wouldn't it just get stripped out when it hit the link-tracker? I don't see any way for the link-tracker to "pass on" anything added to the URL that's "visible" on the affiliate page.

    This may all be becoming a little convoluted. I don't know. :confused:



    At any rate, I'm really, really appreciative of the help I've received.

    Merci bien!
    TheNightOwl
    Signature
    {{ DiscussionBoard.errors[2446673].message }}
  • Profile picture of the author TheNightOwl
    P.S.

    I just doublechecked and the code Jeff suggested was:

    $tid = strip_tags($_GET['tid']);
    // you probably should further sanitize this input
    header( 'Location: hxxp://mylinkhere.com/?tid=' . $tid );


    - Does this do something different to stripslashes?
    - Which one is better?
    - Can they be used together?

    I found some interesting things HERE. (Most of which I don't understand!)

    Thanks!
    Signature
    {{ DiscussionBoard.errors[2446714].message }}
  • Profile picture of the author SteveJohnson
    The thing you're trying to guard against mainly is MySQL injection tactics. Hackers know that any URL with a query string is probably going to be processed by accessing a database at some point. Google "MySQL injection attack" for more information.

    The short course is that the bad person will add a MySQL query to the URL in hopes of compromising the database. In order to do that, any quote marks in the URL need to be "escaped", in other words, prepended by a backslash. The stripslashes function strips out those backslashes, resulting in an invalid, hence harmless, URL.

    Someone would have to know the URL of that redirect picking up the tid to do any damage, wouldn't they?
    No, they wouldn't, and therein lies the danger. People with too much time on their hands will run injection attempts on any url that they suspect is harboring a database.

    Since you know the form your tid is ( alpha-numeric only ) you can use a regular expression to filter out bad requests. If the request contains illegal characters, you don't process it. So:

    PHP Code:
    tid stripslashes( $ _GET['tid'] );
    if ( !
    preg_match'/^a-zA-Z0-9-_/', $ tid )
       
    ## if  contains only letters, numbers, hyphen, or underscore,
       ## go ahead and redirect
       
    header"Location: htxp:mynewurl.com?tid=$ tid" ); 
    ( strip out the spaces after the dollar signs in the variables, this editor is choking on those )

    Here's what the above does:
    1. get rid of any backslashes in input
    2. match against a regular expression allowing only alpha-numeric, hyphens, and underscores
    3. if there is no match ( ! or NOT ), go ahead and redirect. if there is a match, do nothing

    Might be kind of hard to understand. What we're looking for is a false return from preg_match. We want to match any character EXCEPT ( the ^ sign in the reg expression) a-z, A-Z, 0-9, - or _. If there IS a match, this means it's an unwanted character, so the function returns true. If there is no match, it means the string has only acceptable characters so shouldn't be a danger.

    Clear as mud?

    BTW, strip_tags does nothing but remove HTML tags from the string, useless for our purposes.
    Signature

    The 2nd Amendment, 1789 - The Original Homeland Security.

    Gun control means never having to say, "I missed you."

    {{ DiscussionBoard.errors[2447052].message }}
  • Profile picture of the author TheNightOwl
    Heya, Steve

    Really appreciate your help.

    Clear as mud?
    Not at all. I read about MySQL injection attacks just the other day over here. I'd heard the phrase before, but didn't really know what it meant.

    I don't really understand all the syntax of your code there, but from your gloss I do understand what it's supposed to achieve. (Its logic seems a little counter-intuitive at first, but I get the intended functionality.)


    I tried that code. This is what I get, unfortunately...

    Parse error: syntax error, unexpected T_STRING in /home/filepath/bigoldjuicyapples.php on line 6

    Booooo~~~~~!

    I double-checked that I'd removed the spaces. I double-checked the final semi-colon. I changed double-quotes to singles. All no go.

    Not sure why.

    Any ideas?



    P.S. On a sidenote, when I slapped "unexpected T-STRING" into the almighty G-oracle, it returned this neat little two-page affiliate site: http://www.parse-error-unexpected-t-string.com Great, innit?
    Signature
    {{ DiscussionBoard.errors[2447789].message }}
  • Profile picture of the author SteveJohnson
    Ay yi yi. Need an extra closing parentheses on the preg_match line, sorry about that.
    Signature

    The 2nd Amendment, 1789 - The Original Homeland Security.

    Gun control means never having to say, "I missed you."

    {{ DiscussionBoard.errors[2448181].message }}
  • Profile picture of the author TheNightOwl
    Dude, did I mention you rock!

    Thank you very, very much. I'm super appreciative of the tech help I get from folks on this forum. Just little things here and there, but they sure do make a big difference for people like me who know enough to be dangerous and no real need or inclination (or the time!) to become an expert.

    Where's that "Buy Steve a Beer" button gone?

    Thanks again,
    TheNightOwl
    Signature
    {{ DiscussionBoard.errors[2451535].message }}

Trending Topics