PHP Tutorials
91. Iterating Through an Array in PHP
By: David Sklar : 2008-12-01
Description: With foreach, PHP iterates over a copy of the array instead of the actual array. In contrast, when using each() and for, PHP iterates over the original array. So, if you modify the array inside the loop, you may (or may not) get the behavior you expect
92. Password protecting a page in PHP
By: David Sklar : 2008-12-01
Description: When a browser sees a 401 header, it pops up a dialog box for a username and password. Those authentication credentials (the username and password), if accepted by the server, are associated with the realm in the WWW-Authenticate header. Code that checks authentication credentials needs to be executed before any output is sent to the browser, since it might send headers. For example, you can use a function such as pc_validate(), shown in code below.
93. Deleting Cookies in PHP
By: David Sklar : 2008-12-01
Description: It's a good idea to make the expiration time a few hours or an entire day in the past, in case your server and the user's computer have unsynchronized clocks. For example, if your server thinks it's 3:06 P.M. and a user's computer thinks it's 3:02 P.M., a cookie with an expiration time of 3:05 P.M. isn't deleted by that user's computer even though the time is in the past for the server.
94. Reading Cookie Values in PHP
By: David Sklar : 2008-12-01
Description: A cookie's value isn't available in $_COOKIE during the request in which the cookie is set. In other words, the setcookie() function doesn't alter the value of $_COOKIE. On subsequent requests, however, each cookie is stored in $_COOKIE. If register_globals is on, cookie values are also assigned to global variables.
95. Using HMAC Verification in PHP
By: Andi, Stig and Derick : 2008-11-23
Description: If you need to prevent bad guys from tampering with variables passed in the URL (such as for a redirect as shown previously, or for links that pass special parameters to the linked script), you can use a hash, as shown in the following script:
96. Using PEAR::Crypt_HMAC in PHP
By: Andi, Stig and Derick : 2008-11-23
Description: The Crypt_HMAC class implements the algorithm as described in RFC 2104 and can be installed with pear install crypt_hmac.
97. Using Cookies in PHP
By: Andi, Stig and Derick : 2008-11-23
Description: One simple way to maintain data between the different pages in a web application is with cookies. Cookies are sent by PHP through the web server with the setcookie() function and are stored in the browser. If a time-out is set for the cookie, the browser will even remember the cookie when you reset your computer; without the time-out set, the browser forgets the cookie as soon as the browser closes. You can also set a cookie to be valid only for a specific subdomain, rather than having the cookie sent by the browser to the script whenever the domain of the script is the same as the domain where the cookie was set (the default). In the next example, we set a cookie when a user has successfully logged in with the login form:
98. Using Sessions in PHP
By: Andi, Stig and Derick : 2008-11-23
Description: A PHP session allows an application to store information for the current "session," which can be defined as one user being logged in to your application. A session is identified by a unique session ID. PHP creates a session ID that is an MD5 hash of the remote IP address, the current time, and some extra randomness represented in a hexadecimal string. This session ID can be passed in a cookie or added to all URLs to navigate your application. For security reasons, it's better to force the user to have cookies enabled than to pass the session ID on the URL
99. Handling BLOB in PHP and MySQL
By: Andi, Stig and Derick : 2008-11-23
Description: BLOB stands for Binary Large OBject and refers to binary data, such as JPEG images stored in the database.
100. File Handling in PHP
By: Andi, Stig and Derick : 2008-11-23
Description: Let's begin with the basic file-accessing functions. Originally, those functions only worked on normal files, so their names begin with "f," but PHP extends this to almost everything. The most used functions for file access afopen() Opens a handle to a local file, or a file from an URL