Is it the best way? How else are you going to do it?
Some would say it's better to keep the info in a database, because some people don't allow cookies, and it prevents cookie tampering, but for a chatroom, maybe it dosn't matter?
Of course you will have to create all the pages on the fly, but that is what cgi is all about. You can greatly reduce the amount of work the cgi has to do, by making pre-made templates of pages, and just adding the custom cookie data to it. Most monks recommend Html::Template, but for simple pages, you can put the html in "here docs" and just fill in the $username and $city variables "on the fly". There are plenty of here-doc examples around.
I'm not really a human, but I play one on earth.
flash japh