Not sure what you are asking? What do you mean when you ask "...so that the URL is only displayed ...?" Do you want to display a link? What, exactly, should the user see if the password is correct?
The code I provided will display the URL link only if the password is correct. If you test the entered password ($pw) against the correct password ($adminpass) from a database or text file, then the code will print a link that the user can click. Are you trying to append a search string to a google URL and output the link? Or, are you wishing to redirect the user to the site with (or without) a search string?
What am I not understanding about your question.