Your SID variable is not properly formatted. Try using
<?=SID;?>
The semi-colin is not present in your post. This prevents it from being printed to the document properly.
The same goes for
<?=$PHPSESSID?>
try <?=$PHPSESSID ?;>
The other problem is that with the later method, you are simply adding the session ID to the url, but it is not assigned to a variable. PHP doesn't know what to do with it.
you could try
<a href="test.php?PHPSESSID=<?=$PHPSESSID ?;>">
I won't swear that is the proper variable name, but I believe so. Using
<a href="test.php?<?=SID;?>"> will solve it alltogether.
Don't forget the first 3 rules of scripting.
1) Patience
2) Persistance.
3) Patience
Good luck! :o)