You really can't do this like you want for two reasons:
1) The end user could have scripting disabled thereby rendering this solution useless.
2) There would have to be an immediate server call (page refresh) to ensure that the resource was added.
Now being armed with that information if you still want to do it this way here is how.
Step 1)
put this html on every page, before any other forms:
<form action="director.php" method="post">
<input type="Hidden" name="UserID" value="" />
<input type="Hidden" name="AddToMyLinks" value="0" />
<input type="Hidden" name="URL" value="" />
</form>
but be sure that if the person is logged in you pull their userid from their session into the value for UserID
Step 2)
put this javascript on every page
<script>
function SetAddResource(ResourceID) {
if(document.forms[0].UserID.value == '') {
alert('You must be logged in to add resources to your links.');
return(0);
} //end if
if(confirm('Click ok to add ' + ResourceID + ' to your links.')) {
document.forms[0].AddToMyLinks.value = ResourceID;
} //end if
return(1);
} //end SetAddResource
function GotoURL(URL) {
document.forms[0].URL.value = URL;
document.forms[0].submit;
} //end GotoURL
</script>
Step 3) The links on the page are not hyperlinks to other pages but instead look like this.
<a href="javascript:GotoURL('thelink.php');">Link</a>
Step 4) director.php contains code like this.
<?php
if(isset($_POST['AddToMyLinks'] && $_POST['AddToMyLinks'] != '')) {
//code to add the link to their links
}
if(!isset($_POST['URL'])) {
//do something if no URL is provided
}
header('Location: " . $_POST['URL']);
?>
WARNING I did not test this code it probably has loads of syntax errors and maybe a couple of logic errors as well.