In December someone here asked if it was possible for associates to link
directly to multiple pages on a site, without having to set up multiple
associate accounts. It's certainly a useful feature in a lot of cases; we
sell music, so our associates would often want to link directly to certain
artists or albums, not just the homepage.
I think I've found a way to do it, so I thought I'd through it out here for
the general benefit... or, if I've overlooked some fatal flaw you can see,
I'd appreciate the tip.
When setting up a new associate account in the back office, you'll set their
"Store page" URL to a new file that you'll create; in my case, I'm using
PHP, but you could use any dynamic environment: perl, ASP, coldfusion i
suppose, whatever. In my case, each associate's "Store page" is set to
"http://mystore.com/associategateway.php".
Now, just create that file. It needs to look at the environment for the
variable containing the referer URL, which will be the actual URL that the
user linked to. You can then parse the URL and pick out any GET values it
contains, and redirect the user accordingly. Here's the PHP script I wrote.
////////
$referer=$HTTP_SERVER_VARS[HTTP_REFERER];
if(!$referer) { // if there's no referer, just go home
$loc='/';
} else {
$url=parse_url($referer);
$parts=split('&', $url['query']);
foreach($parts as $part) {
list($k, $v) = split('=', $part);
if($k=='artist') {
$loc="/artist.php?id=$v";
} else if($k=='album') {
$loc="/album.php?id=$v";
} else if($k=='channel') {
$loc="/channel.php?channel=$v";
} else {
$loc='/';
}
}
}
Header("Location: $loc"); // causes an http redirect
exit;
////////
As you can see, in my case I'm checking to see if certain variable names are
passed as GET values in the URL, and then assembling the correct URL for
them. A more general approach, which I'll leave as an excercise for the
reader, would be to URL-encode an actual path and/or filename, and simply
redirect the user to that path. With such a script, your associate could
link directly to your product X with a URL of this form:
http://yourstore.com/cgi-bin/sb/ref.cgi ... tename&url
=productx.html
Obviously, this implementation requires PHP, but the idea should be portable
to any environment.
One possible problem: I'm not sure how the referer URL is passed. If it
comes from the server, this should always work; if it comes from the
browser, it's possible that some browsers wouldn't report it, or wouldn't
report it the same way. If anyone knows the answer, I'd appreciate it.
Hopefully this is helpful.
:scott raymond
sco@grassrootsmusic.com