I think we really need more information than you are giving us (such as the rest of your script). My suggestion would be to get a client that can show you the HTTP headers (
cURL for instance), and make sure that the script and server are sending the browser exactly what you want it to.
-caedes