you can do this as follow.
Before sending a response to the browser, you process all links in your website and pass your session id.
# you should check that a session has already started. if not start it
# before issuing the following statement
$my_id = "?the_ID=" . $_SESSION['the_ID'];
# now locate all of your links and append the above variable
I don't know how you are storing your links i.e. files, or in database.
if in a file... you need to use a regular expression to append the session id in the file. Note: can affect server performance