You can't via CGI. Your best bet is to configure the webserver to always run some script before every other script, or something similar. For example, using apache and mod_perl, it is possible to configure a script that runs after every request and gets the full content that would be sent back to the request.