Session usage PHP4.0 has a feature that has always been expected, which is supported by PHP sessions. In contrast, PHP3.0 users have to use third-party libraries or do not have the functionality at all. Lack of session support is one of the biggest defects of PHP, and is also the most widely recognized part. SyntaxHighlighter. all ();
Session usage PHP 4.0 has an always-expected feature, which is supported by PHP sessions. In contrast, PHP 3.0 users have to use third-party libraries or do not have the functionality at all. Lack of session support is one of the biggest defects of PHP, and is also the most widely recognized part. However, as session support has become part of the latter since the early version of PHP 4.0, this obstacle also disappears. With session support, you can maintain user-specific variables during user access to the network site without having: set multiple cookies, use hidden form fields, or store information in a database that you may frequently connect. Starting a session on a page tells the PHP engine that you want to start a session (if not) or continue the current session: session_start (); when a session is started, an identifier string (such as 940f8b05a40d3169c030c9c7745aead9) is sent to the user through a cookie. a temporary file that matches this is created on the server. in the preceding example, the name is like this: sess_940f8b05a40d3169c030c9c7745aead9. This file contains the registered session variables and their assigned values. User access counters are the most common examples of using Sessions: start your PHP module and ensure that the PHP code is the first line of the File: No blank, no HTML output, and so on. This is because when the session function sends a file header, if you send blank or HTML code before the session_start () function, the system reports an error.
Youve been here $ count times.
"; The entire access counter code is as follows: Youve been here $ count times.
";?> If you reload the preceding script, you can see that the count value has increased. Interesting? You can also register arrays in sessions. Suppose you have an array named $ faves: $ faves = array (chocolate, coffee, beer, linux); you can register this array like other single variables: session_register (faves ); there is no difference between the index array and other single variables, such as $ faves. If your users want to show their hobbies on a Web site page, you can register what they like as a session variable named $ faves, then you can print these values on other pages: "; While (list (, $ v) = each ($ faves) {echo"
$ V ";} echo"";?> This is what you need: a beautiful list of user hobbies. Session variables cannot be overwritten by query strings. that is to say, you cannot type http: // www.yourdomain.com/yourscript.php? A command like count = 56 assigns a new value to the registered session variable $ count. This is very important for security: you can only modify or delete (unregistered) session variables on the server script. If you want to completely delete a session variable, you can cancel registration of the variable from the system: session_unregister (count); permanently delete a session, for example, pressing the Logout button, then you can write down the following code: session_destroy (); using sessions to store variable values can save us from the pain of writing database processing code, so as not to overload the system, at the same time, it also reduces the scope of use of the proprietary database syntax. besides, you no longer have to send a lot of cookies to the users who visit the site. Now, we can get everything done with just one cookie and one variable. a drop of water shows all the glory! It cannot be simpler.