yes, that should work, just make sure on the cart page that the code to set the session variable:
<?php
if (!session_id()) session_start();
if((isset($_GET['guest']) && $_GET['guest'] != "")) {
$_SESSION["UserID"] = "0";
}
?>
is before the page access restriction code.