Parse the included JavaScript file as PHP
Create a .htaccess file in you JavaScript directory and add the following line.
AddHandler php-cgi .js
<?php ?>
tags till now be recognized by your JavaScript file.
Use Ajax to fetch the user ID
Create a file called getID.php which only echoes the users ID. Then in your JavaScript file you can use the following code.
$.get('getID.php', function(uid) {
alert('User ID is:' + uid);
});
Create a script tag before including the JavaScript printing user ID.
<script type="text/javascript">
userID = <?php echo $_SESSION['user']; ?>;
</script>
You will now have access to the users ID using variable userID.