Frequently Asked Questions
These questions are meant help you solve specific but common problems that may pop up when using this language. They are meant to be read after you have gone through the tutorial and begin actual development.
Many of these questions and answers are taken from the official php.net faq maintained by the developers of php. If you can't find the question(s) you are looking for on this page try searching through that page.
How can I pass a variable from Javascript to PHP?
Since Javascript is (usually) a client-side technology, and PHP is (usually) a server-side technology, and since HTTP is a "stateless" protocol, the two languages cannot directly share variables.
It is, however, possible to pass variables between the two. One way of accomplishing this is to generate Javascript code with PHP, and have the browser refresh itself, passing specific variables back to the PHP script. The example below shows precisely how to do this -- it allows PHP code to capture screen height and width, something that is normally only possible on the client side.
Refer to this url for an example of a php script that would accomplish this task.
How can I securely store data?
For a variety of reasons you may want to store a piece of information in a way that ensures no unauthorized access occurs. This might be a user's password or social security number. Simply putting the piece of information in a secured database is not enough. In order to use this you will need to use a hashing function which magically, using complex mathematics, turns your string into a random mix of characters. For any given string the resulting random mix of characters is always the same allowing you to know if two pieces of data are the same without actually knowing what they are.
We recommend using crypt() because for most cases this will accomplish what you need without complication of the problem. Using crypt() is as easy as passing in a string and getting a hashed string in return. You can then compare hashes to see if a hashed string is equal to another hashed string.
You will want to refer to the crypt() php.net manual for further description on how to use it along with code samples.

