that first code should work for clearing the cart but leaving the user logged in, if it is not leaving the user logged in, there must be another session variable that is used by the login system.
to help troubleshoot, lets take a look at the login system. After login, what page is the user redirected to? Open that p[age and add the following code just after the <body> tag to write the session contents:
<pre><?php var_dump($_SESSION); ?></pre>
I'm guessing that in addition to the username and user password session variable, there is a use ID session that needs to be reset as well.