Erro pages customization in production environment


In my application i had two error pages for 500 and 404 error.
500.html and 404.html
when someting went wrong this pages is called. but this pages are
static pages if i want to add some dynamic data how i can add in it?
say user A’s session going on and he click some bad url or
something so
i wan t show user A’s name and other data n 500.404.html page.

Please help me to find this? and find how to configure this error
pages in application