Stiamo andando fuori tema.

Comunque non conosco PHP, per cui non ti so aiutare.
Io lo ho fatto in Perl (CGI).

Ciao
Michele