Fwrite (file handle, write content) return value is the length of bytes written to the file
fopen (file path, open mode) This is the file handle.
Fclose (file handle) Close file handle
After the file handle is opened, you can read and write to the file, and closing the file handle will no longer read and write to the file.
Copy (copied file path, file path after copying) copying files
Store location to include file name
Unlink (file path) Delete file
Filemtime (file path) returns the time when the file was last modified and a timestamp was obtained
FileSize (file path) returns the size of the file, in bytes
Request protocol Package for http:
1, Request line (Request-line)
Request mode-Request path-protocol version
Requires a separate row, the path does not include the domain name
2, request header (Request-line)
The collection of all protocol entries that are required for this request
Host: Indicates the hostname (domain name) of the requesting server
Accept-encoding:gzip indicates the type of file compression encoding supported by the browser
Accept_charset: Browser-supported character set
Referer which URL this request came from
Accept-language: Acceptable language types
Cookie: Cookie Data If there are no expired cookies on the site
User-agent: Kernel information for the browser
Accept: Data types acceptable to the browser
3, empty line
Used to separate the request header from the request data, the table name request header to this end
4, request data (Request-line)
The requested data is stored here, such as personal information entered when registering an account.
Use Telnet to send a request to the server
In cmd: 1,telnet 192.168.148.10 80
2,ctrl+] The echo of the data
3, enter request line, request header, blank line
Each Telnet send request can only be a single time, re-use need to turn on Telnet
About the appropriate protocol package for http:
1, Response line (status line)
Protocol version, Status code (404: Request resource does not exist), status description
Common Status Codes:
OK: Request successful
302 found: Redirect, with the response header location used, the server requires the browser to re-initiate a request
404 Not Found: Request resource does not exist
403 Forbidden: No access to the resource
Server Internet Error: Internal errors, not responding properly
Exclusive row
2, response header (also a collection of some protocols)
A collection of protocols
Protocol Name: Value
Server: Servers information
Date: Response time
Last-modified: File Last Modified
Content-length: Length of response body (bytes)
Content-type: The data type of the corresponding content-text/html image/png
Location: Redirect, browser encounters this option to jump immediately, will not parse the later content
Refresh: Redirect, browser encountered this option will be ready to jump, time will jump, continue to parse down
Content-encodeing: File Encoding format
Cache-control: Cache control, no-cached-do not cache
3, empty line
4, Response body (corresponding data)
PHP Analog HTTP response
Through the header () function
Header ("Protocol Name: Protocol value");
Header ("Content-type:text/html;charset=utf-8"); Set file encoding
Header ("Location: New URL or uri"); Set jump, the browser accesses to the row to jump (inside the station with the URI)
Header ("Refresh: The time the wait is refreshed; Url=url or URI") during the wait process, the following code will continue to execute
Verification Code
PHP default does not handle the function of the picture, so to load the GD library (image processing extension)
Php.ini--extension=php_gd2.dll
Canvas: Imagecreate (width,height); (256 colors)
Imagecreatetruecolor (Width,height); (24-bit True color) (general use)
Color handle: Imagecolorallocate (Img,red,green,blue);
IMG: Canvas Resource
Draw text: imagestring (img,size,x,y,sting,color);
Size: Text sizes
X, y: Starting coordinates (the origin is the upper-left corner)
String: Text content
Color: Handles to Colors
Image<png|jpeg|gif> (canvas resource [, save path])
The output is to use the header function to set the corresponding header information, tell the browser this is a picture
Clean up data buffers with Ob_clean () before output
1, fill background
A) Imagefill (Img,x,y,color); Fills the area with the same color and continuous field.
IMG: Canvas Resource
X, y: Coordinate points
Color: Handles to Colors
2, add interference line
A) imageline (Img,x1,y1,x2,y2,color);
3, add noise (interference point)
A) Imagesetpixel (Img,x,y,color);
Code implementation:
1. img = Imagecreatetruecolor (170,40);
2. BackColor = Imagecolorallocate ($img, Mt_rand (180,255), Mt_rand (0,255), Mt_rand (180,255));
3. Imaggefill ($img, 0,0, $backcolor);
4. $arr = Array_merge (range (' A ', ' Z '), rang (' A ', ' Z '), Range (0,9));
5. Shuffle ($arr);
6. $rand _keys = Arr_rand ($arr, 4);
7. $str = ";
8. foreach ($rand _key as $value) {
$str. = $arr [$value];
}
9. $span = Ceil (170/(4+1));
for ($i =1; $i <=4; $i + +) {
$strcolor = Imagecolorallocate ($img, Mt_rand (0,100), Mt_rand (0,100), Mt_rand (0,100));
Imagestring ($img, 5, $i * $span, ten, $str [$i-1], $strcolor);
}
One. for ($i =1; $i <=6; $i + +) {
$linecolor = Imagecolorallocate ($img, Mt_rand (5,100), Mt_rand (50,100), Mt_rand (0,100));
Imageline ($img, Mt_rand (0,169), Mt_rand (0,39), Mt_rand (0,169), Mt_rand (0,39), $linecolor);
}
for ($i =1; $i <=170*40*0.03; $i + +) {
$pxcolor = Imagecolorallocate ($img, Mt_rand (0,255), Mt_rand (0,255), Mt_rand (0,255)
Imagesetpixel ($img, Mt_rand (0,169), Mt_rand (0,39), $pxcolor);
}
Header ("Content-type:image/png");
Ob_clean ();
Imagepng ($IMG);
12-8-Protocol, request, response, canvas (verification code production)