So far this is how i've gone about it. Perhaps it will be helpful to others, if not and there are problems with this I shall delete the answer.
When I load the item page I update my DB with an identifier, category, id number, location, time started using NOW() and I update the time left as NOW() also.
Then within the page itself I run this javascript.
<script>
// Set url for JavaSCript
var url = '<?php echo Yii::app()->createUrl("item/viewedItemInformation"); ?>';
var item = '<?php echo $model->id; ?>';
var data = [{name: 'item', value: item},
{name: 'async', value: false}];
// call function to see if still on page
var onPage = setInterval(function() {
<?php echo CHtml::ajax(array(
'url'=>'js:url',
'data'=> "js: data",
'type'=>'post',
'dataType'=>'json',
));
?>
}, 5000);
So that script runs every 5 seconds and calls another controller function that searches for the record in the DB and updates the time_ended with the time the controller function was called using NOW()
also.
Hope that makes sense, I've only tested it a little bit, so I'll need to do a bit more with this. If anyone sees any problems with it let me know.
Update
So far this script seems to be working fine. I'm only working on my localhost and I have LinkedIn plugins and they seem to stop the script working. I keep getting this error: I've never noticed it before. I have recently reinstalled my XAMPP so might not be aware of any other differences between set up. I'm also not sure why the plugin would seem to stop my JS script working?
Origin http://localhost is not allowed by Access-Control-Allow-Origin.
Jonnny