If you are using PHP4 I suggest you use sessions. If you are not using PHP4 I suggest you upgrade (if possible) to PHP4 and use sessions.
There are a few good session tutorials right here on phpbuilder.com to lead you through.
It sounds like you are trying to reinvent the wheel.
If you don't have the option to upgrade to PHP4 then I suggest you check out PHPLIB and use their session libraries.
Good Luck.