How can I have a password inside PHP code and guarantee that no one viewing the page in the browser can retrieve it?
Is:
That depends on the type of passwords you want to store.
If you want to store passwords to compare against, e.g. having an $users
array, then hashing is the way to go. sha1, md5 or any other flavor (here’s an overview)
Adding a salt accounts for additional security, because the same password will not result in the same hash
Update: password_hash uses a salted, strong one-way hash with multiple rounds.
If you want to store passwords to connect to other resources like a database: you’re safest if you store your passwords outside your document root, i.e. not reachable by browsers. If that's not possible, you can use an .htaccess
file to deny all requests from outside