Step 29 – Transferring the SCO Instance ID

In my last post, I looked at the changes that I needed to make to the “scormvars” database table, and to the database-specific functions in the subs.php file to support the SCOInstanceID.

Now, I have to figure out how to get the value of the SCOInstanceID from the LMS which initiates the session, through the client-side JavaScript API code, to the server-side PHP API code and then to the subs.php file. In other words:

Transferring the SCO Instance ID from the LMS to the API Code

I’m going to start with the rte.php file. I’m going to assume that the LMS passes the SCOInstanceID to the code as a GET variable i.e. encoded as part of the URL. Obviously, you’ll have to change this if the LMS does it some other way but, for now, this will do. All I have to do within rte.php is to transfer the value of SCOInstanceID to the next link in the chain – api.php. So here’s what the new version of rte.php looks like:

<?php 

// read SCOInstanceID from the GET parameters
$SCOInstanceID = $_GET['SCOInstanceID'] * 1;

?>
<html>
<head>
	<title>VS SCORM</title>
</head>
<frameset frameborder="0" framespacing="0" border="0" rows="0,*" cols="*">
	<frame src="api.php?SCOInstanceID=<?php print $SCOInstanceID; ?>" name="API" noresize>
	<frame src="../course/index.html" name="course">
</frameset>
</html>

As you can see, I’ve added some PHP code to read the value of SCOInstanceID from the URL (line 4), and then some more PHP code (line 12) to pass this value to the api.php script as a GET parameter. Also note that I’ve renamed rte.html as rte.php, and api.html as api.php since they now contain PHP code. Pretty straightforward so far.

Now moving on to api.php which contains the client-side JavaScript API that communicates with the server through AJAX calls. This has to be modified so that the value of SCOInstanceID is included in every AJAX call. As in rte.php, I add the following PHP code to api.php:

<?php 

// read SCOInstanceID from the GET parameters
$SCOInstanceID = $_GET['SCOInstanceID'] * 1;

?>

Now, I modify each of the AJAX calls in api.php to include the value of SCOInstanceID as a GET parameter – for example:

// set up request parameters - uses GET method
req.open('GET','initialize.php?SCOInstanceID=&code='+d.getTime(),false);

This will then be passed to initialize.php, getValue.php, setValue.php and finish.php – the next links in the chain. Each of these files needs to read the value of SCOInstanceID passed through the AJAX call, and then transfer it to the database-specific code in the subs.php file. This is actually very easy since the functions in subs.php assume that the PHP variable $SCOInstanceID is a global variable. So, all that I have to do is to add this code to the top of the initialize.php, getValue.php, setValue.php and finish.php files.

<?php 

// read SCOInstanceID from the GET parameters
$SCOInstanceID = $_GET['SCOInstanceID'] * 1;

?>

And that’s it.

Since I haven’t posted detailed listings for each of the files, next time I’ll make some changes to the utilities code (index.html, ./utils/cleardb.php, and ./showdb.php), then post a link to a code bundle for you to download.

This entry was posted in Run Time Environment. Bookmark the permalink.

1 Response to Step 29 – Transferring the SCO Instance ID

  1. Daniel says:

    I was wondering why you’re not using $_SESSION to track the $SCOInstanceID – Is there some reason to use get variables (which the user could mess with, not that it’d do them much good I guess) over _SESSION? (also using session variable is better than global, and keeps the value hidden from the user)

Leave a Reply

Your email address will not be published. Required fields are marked *