This is definitely possible with some creative PHP coding
This is what will happen:
-User clicks the advertisement on the original site
-The user will land on PAGE1 of your site, which will have a javascript redirect to PAGE2 (javascript redirects yield a referer that equals the page it's on)
-PAGE2 two will check the referer to see where the user came from. If they came from PAGE1, then the page will display another javascript redirect to send them to your affiliate site. (With PAGE2 being the referer.) If they came from anywhere else, the page will display its normal static content.
It is also possible to send the orig ad directly to page two, assuming you know all the places your ad will be displaying. (And so what referer the user will have when they click it.) This depends fully on how the ads work/where they are--but the method I listed with 2 pages should work in any case.