Learning
Other features of the 5.PHP: crystal5 Other miscellaneous 5.1 PHP can manipulate image generation process images. If you have already installed a GD library, you can even use a PHP to generate an image. Header ("Content-Type: Image / GIF"); $ String = Implode ($ Argv, "); $ IM = ImageCreateFromgif (" Images / Button1.gif "); $ ORANGE = ImageColoralLocate ($ IM, 220 , 210, 60); $ PX = (iMagesX ($ String) / 2; ImageString ($ IM, 3, $ PX, 9, $ String, $ Orange); Imagegif ($ IM ); ImageDestroy; (Translator Note: The above code segment is missing, please refer to the image processing function part of PHP Manual) This code is in other pages Call, then the above-described button.php3 code acquires the Text value and add this value in another image file - the image file in the above code is images / button1.gif - final output Go to the browser. If you want to use the image button in the form field, it is not desirable to regenerate a new image after the text on each button will be changed, and the image file can be dynamically generated using such a simple method. 5.2 Cookies PHP supports http-based cookies. You can use cookies as needed in need of using a general variable. Cookies is some information segments that are saved on the client, so you can know if anyone on a specific PC has visited your site, and the viewer is in your site. Traces, etc. A typical example of using cookies is the screening of the browser preference. Cookies is set by the function setCookie (). Like the function header () output HTTP header, setCookie () must be called before any actual content cup is output to the browser. The following is a simple example: If (Empty ($ VisitedBefore)) {// If you do not set a cookie, the last parameter in the current time value // function is declared for the cookie to save the time // This example is a 1 year // time () function returns to the time SETCOOKIE ("Visitedbefore", Time (), Time () (60 * 60 * 24 * 365) ));} Else {// Welcome to visit Echo "Hello the, Welcome Back
" again; // Read cookie and determine if IF ((Time () - $ visitedbefore)> = "(60 * 60 * 24 * 7) ") Echo" Why Did You Take A Week To Come Back. You Should Be Here More Often !? ";}?> 5.3 Based on HTTP Verification Based on HTTP Verification When PHP cannot be implemented when the CGI mode is run. We can use the function header () to send HTTP header forced verification, and the client browser pops up a dialog box for entering the username and password. These two variables are stored in $ PHP_AUTH_USER and $ PHP_AUTH_PW, you can use these two variables to verify legality and allow access.
The following example passed the user name / password to the verification of TNC / Nature, a user's login: If ($ pHP_AUTH_USER) {header ("www-authenticate: Basic realm = /" my realm / "" HEADER ("http / 1.0 401 unauthorized"); echo "text to send if user hits ca Zancel button / n"; exit;} else {if (! ($ PHP_AUTH_USER == "TNC" && $ PHP_AUTH_PW == "Nature ")) {// If it is a wrong user name / password pair, forced re-verification header (" www-authenticate: Basic realm = / "my realm /"); Header ("http / 1.0 401 unauthorized); echo "Error: $ PHP_AUTH_USER / $ PHP_AUTH_PW Is Invalid."; Exit;} else {echo "Welcome TNC!";}?> In fact, it is unlikely that the user name / password pair, Instead, use the database or encrypted password file to access them. 5.4 File Upload You can use the PHP implementation file function, pay attention to the client's browser should be Netscape3 or more or more.
The following is a simple demonstration of this feature: