It depends on how you want this to show up. If you want it in your traffic logs you should dynamically build the links on the product list page.
Code:
$ref = $_REQUEST['ref'];
$link = "http://some.place/some.page?$ref";
echo "<a href=$link>Page Title</a>\n";
$link = "http://some.place2/some.page2?$ref";
echo "<a href=$link>Page Title 2</a>\n";
Alternately, if you don't need complete stats, you could just stuff the value into a session.
Code:
$_SESSION['ref'] = $_REQUEST['ref'];
Then, when the user arrives at the final PHP page, even perhaps to provide for a PDF download, you could stuff the session reference value, if it was set, into a database.
Code:
$ip = $_SERVER['REMOTE_ADDR'];
$sql = "BUILD INSERT WITH $ip and $_SESSION['ref']";
mysql_query($sql);
I hope that is what you meant.