Are you high?
lol
If you are serious, do it in php and before the <html> tag put:
PHP Code:
<?php
$ref = $_GET['ref'];
?>
then in the links put:
PHP Code:
<?php
print "<a href=http://www.site.com/ref?ref=".$ref.">text</a>";
?>
But first lay off of the sauce so we can understand you...