in reply to 302 Found Location Message

print header; print start_html("Login"); ... print redirect("http//");

You can't use both redirect and output something else to the browser. If I understand what your code is doing, you probably want to wait with outputting the header and HTML until it's clear the user isn't being redirected.

I see a few more points in your code that could be improved: