Other PHP functions

Source: Internet
Author: User
5. other miscellaneous 5.1 Native images PHP can hold processed images. If you have installed the GD library, you can even use PHP Native images .? Header ("Content-type: image/gif"); $ string = implode ($ argv, ""); $ im = imagecreatefromgif ("images/bu 5. Miscellaneous
5.1 Native images

PHP can handle images. If you have installed the GD library, you can even use PHP Native images.
Header ('content-type: image/gif ');
$ String = implode ($ argv ,'');
$ Im = imagecreatefromgif ('images/button1.gif ');
$ Orange = ImageColorAllocate ($ im, 220,210, 60 );
$ Px = (imagesx ($ im)-7.5 * strlen ($ string)/2;
ImageString ($ im, 3, $ px, 9, $ string, $ orange );
ImageGif ($ im );
ImageDestroy ($ im );
?>
(Note: The above code segment lacks comments. please refer to the image processing function section of PHP Manual)
This code is called through the following mark on other pages, and then the above button. the php3 code obtains the text value and adds the value to the other obtained image file. in the above code, the image file is images/button1.gif and is finally output to the browser. If you want to apply the image button in the form field, but you don't want to see the text on each button have to re-create a new image, you can use this simple method to dynamically create an image file.

5.2 Cookies

PHP supports HTTP-based cookies. When needed, you can easily use cookies as common variables. Cookies are some pieces of information that the browser keeps on the client. Therefore, you can know whether anyone on a specific PC has visited your site, and whether the viewer has logged on to your site. The typical example of cookie application is the screening of viewer preferences. Cookies are set by the setcookie () function. Like the header () function that outputs the 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 no cookie is set, the current time value is assigned to the cookie.
// The last parameter in the function declares the cookie retention time
// In this example, it is 1 year.
// The time () function returns the time in seconds since January 1, January 1, 1970.
SetCookie ('visitedbefore', time (), time () (60*60*24*365 ));
}
Else
{
// Welcome again
Echo 'hello there, welcome back
';
// Read and determine the cookie
If (time ()-$ VisitedBefore)> = '(60*60*24*7 )')
Echo 'Why did you take a week to come back. You shoshould be here more often !? ';
}
?>

5.3 HTTP-based verification

HTTP-based verification cannot be implemented when PHP runs in CGI mode. We can use the function header () to send HTTP header forced verification, and the client browser will pop up a dialog box for entering the user name and password. These two variables are stored in $ PHP_AUTH_USER and $ PHP_AUTH_PW. you can apply these two variables to verify the validity and promise to enter. The following example shows how to verify the login of a user using the user name/password pair tnc/nature:
If (! Isset ($ PHP_AUTH_USER ))
{
Header ('www-Authenticate: Basic realm = \ 'My Realm \'');
Header ('http/1.0 401 unauthorized ');
Echo 'text to send if user hits Cancel button \ n ';
Exit;
}
Else
{
If (! ($ PHP_AUTH_USER = 'tn' & $ PHP_AUTH_PW = 'natural '))
{
// If it is a wrong user name/password pair, force verification again

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.