Hi,
In this scenario, you have 4 domains in play, and you are going to need to have control over 3 of them.
The domains:
1. the Handler domain - this is where you will upload the fake referer script, so it has to be somewhere where you can upload php files.
2. The domain to which you wish to send traffic, this is the destination link, and is the only domain/page involved which you don't need to control at all, it is the advertiser's page, usually, or a CPA offer page.
3. A site to which you either drive traffic, or which already receives traffic, but which is not considered "acceptable" to the Network or Advertiser, for whatever reason. This is your "naughty" site, it's the site which will link to the advertiser's page, but you do NOT want it to appear, anywhere, ever, and
4. Your spoofing referer site - this site IS acceptable to the advertiser's/networks, it's your "nice/clean" site and, although it doesn't really attract any traffic on its own merits, you want it to "appear" as the referer, so the advertiser's think that your traffic is coming from here.
You have to own/control site 4 for two reasons:
a) because you have to upload some php code to it, as explained in the OP, and
b) because you "should" add links to the advertiser's pages, or the CPA offer pages, so, when it is seen as the referer, and gets checked, it appears feasible that your traffic could actually be coming via that site.
So no, unfortunately, you are not going to be able to make "google" or "yahoo" appear as your fake referers...