Well, Ive never realized this problem...
Ok, just a wild guess here (totally not tested): what if you set the var $SERVER['PHP_SELF'] or $SERVER['SCRIPT_NAME'] manually after you end processing your commands?
As I've said, this is a wild guess, let me know if you find a solution.
Best regards,