PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY to (How to cite a web site)
Friday, February 22nd, 2008PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY to gain access to a protected site, the password itself is stored (preferably encrypted) in a separate location, and not as a session variable. Sessions are supported by default, so you don t need any special configuration. However, since they rely on a cookie, sessions won t work if cookies are disabled in the user s browser. It is possible to configure PHP to send the identifier through a query string, but this is not considered safe. Creating PHP sessions Just put the following command in every PHP page that you want to use in a session: session_start(); This command should be called only once in each page, and it must be called before the PHP script generates any output, so the ideal position is immediately after the opening PHP tag. If any output is generated before the call to session_start(), the command fails and the session won t be activated for that page. (See The Headers already sent error section later for an explanation.) Creating and destroying session variables You create a session variable by adding it to the $_SESSION superglobal array in the same way you would assign an ordinary variable. Say you want to store a visitor s name and display a greeting. If the name is submitted in a login form as $_POST[’name’], you assign it like this: $_SESSION[’name’] = $_POST[’name’]; $_SESSION[’name’] can now be used in any page that begins with session_start(). Because session variables are stored on the server, you should get rid of them as soon as they are no longer required by your script or application. Unset a session variable like this: unset($_SESSION[’name’]); To unset all session variables for instance, when you re logging someone out set the $_SESSION superglobal array to an empty array, like this: $_SESSION = array(); Do not be tempted to try unset($_SESSION). It works all right but it s a little too effective. It not only clears the current session, but also prevents any further sessions from being stored.
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.