PHP most full note (v) (worth collecting, from time to times to look over)

Source: Internet
Author: User
Tags dashed line transparent color session id setcookie urlencode alphanumeric characters

Delete

Method 1: Set its value to an empty string

Setcookie (' user[name] ', ');

Method 2: Set the target cookie to the "expired" state.

The lifetime of the cookie is set to expire, and the lifetime is the same as the browser, which is deleted when the browser is closed.

Setcookie (' usr[name] ', ', Time ()-1);

Note

1. Cookies can only hold string data 2. $_cookie is used only to receive cookie data and not to set up or manage cookie data.

Manipulation of $_cookie does not affect cookie data.

$_cookie will only save the cookie data that the browser carries when requested. 3. Cookie life cycle:

Temporary cookie: Deleted when browser is closed

Persistent Cookie: $expire parameter is a timestamp that indicates the time of failure. 4. Valid directory

The cookie is valid only in the specified directory. The default is the current directory and its subdirectories.

The cookie in the subdirectory is not available in its parent directory or sibling directory. 5. cookie-Differentiated domain name

The default is the current domain name and its sub-domains are valid. 6. JS is obtained by Document.cookie, the type is String 7. The browser has no limit on the total number of cookies, but the number of cookies per domain name and the size of each cookie are limited and different browser restrictions apply.

/* "Session" */

1. Open session mechanism

Session_Start ()

Note: There is no output before the Session_Start () function! Unless the OB cache is turned on. 2. Operating data

Manipulating the $_session array

3. Browser-side save SessionID, default to all directories under the current domain name and its subdirectories take effect. That is, the default setting of the cookie's path value is '/'

4. Server Save session data

Default Save method: Each session will generate a sessions data file, the file name is: Sess_ plus SessionID5. Session can store any type of data except for resources.

The data is serialized and then saved to the file. 6. The $_session element subscript cannot be an integral type!

Because only the element values are serialized.

An array subscript within an element does not have this requirement. 7. Life cycle

Default is browser off

Because the browser saves the cookie variable SessionID is temporary

But the server side session data file does not necessarily disappear (need to wait for the session garbage collection mechanism to handle)

The life cycle of the PHPSESSID variable in the cookie can be extended. (Not recommended)

PHP.ini configuration Session.gc_maxlifetime8. Delete data

The $_session variable will still disappear at the end of the script. The $_session variable is created when the session mechanism is opened.

$_session and the file that holds session data are two spaces.

unset ($_session[' key ') simply deletes the element within the array and does not immediately correspond to the file that holds the SESSION data.

The $_session data will not be written to the file until the end of the script.

Session_destroy () destroys the file that holds the session data and does not write to the file.

The $_session variable is not deleted, unset or the script ends before the variable is deleted.

How to completely delete a session? 3 parts need to be removed

Unset ($_session);

After you delete the $_session variable, the data file is not changed. If you use unset alone, you need to first empty $_session = Array ()

Session_destroy ();

Setcookie (' Phpsessid ', ', Time ()-1);//The insurance practice is to invalidate its life cycle throughout the script cycle, reading and writing data files only once.

Rewrite the session's storage mechanism

# Session Storage Mode

Session.save_handler = User|files|memcache

# problems caused by too many data files can be solved by molecular catalog save

PHP configuration file under the Session.save_path option, and you need to manually create a data storage directory.

Add a hierarchy before this configuration option. The principle of distributing subdirectories, using the corresponding letters of the session ID to assign subdirectories. You still need to create subdirectories manually.

Session.save_path = "2; F:/phpjob/temp "

# multi-server data sharing issues

# Data Store Operations:

Initialize $open, release resource $close, read $read, write $write, destroy storage media $destroy (triggers when Session_destroy is called), garbage collection $GC

# The length of the session ID is variable. Different settings result in a different length of session ID.

Session.hash_function allows the user to specify the hash algorithm that generates the session ID.

' 0 ' represents MD5 (128-bit), and ' 1 ' represents SHA-1 (160-bit).

Session.hash_bits_per_character allows a user to define how many bits per character are stored when converting binary hash data into a readable format.

The possible values are ' 4 ' (0-9,a-f), ' 5 ' (0-9,a-v), and ' 6 ' (0-9,a-z,a-z, "-", ",").

Total hash length is 128bit, session ID length is 128/possible value, 4->32, 5->26, 6->22

# Custom data Store action methods

Note: Do not care about how PHP serializes, deserializes, how to get data and write data, only the operations associated with data storage Session_set_save_handler

Set user-defined session data store functions

BOOL Session_set_save_handler (callable $open, callable $close, Callable$read, callable $write, callable $destroy, Callable $GC)

Execution order: Open, close, read, write, destroy, GC

# Set the processor first, then turn on the session

# Common functions

Session_Start Open or Resume session mechanism

SESSION_ID Gets or sets the current session

Idsession_destroy destroying all data for the current session (destroying data files)

Session_name Gets or sets the current session name (cookie variable name, default = PHPSESSID)

Session_save_path Gets or sets the current session data file save path

Session_set_save_handler setting user-defined session data store functions

Session_unset Releasing all session variables (emptying $_session array elements)

Session_encode encode the current session data as a string

Session_decode translating a string into session data

Session_write_close write session data and close sessions

Session_register_shutdown Closing a session

Session_set_cookie_params sets the session cookie variable, which must be used before session_start ().

Session_set_cookie_params (0, "/webapp/");

Set session Survival time

Session_get_cookie_params gets the session cookie variable. Returns an array containing the current session cookie information

# Configuration

Php.iniini_set ($varname, $newvalue);

The function's configuration is only valid for the current script

Not all php.ini settings can be set by this function Ini_get ($varname)//Get a configuration item information Ini_get_all ([str $extension])///Return all configuration item information

Array

# Session Extension Configuration

SESSION.NAME Specifies the session name to use as the name of the cookie. Can only be made up of alphanumeric characters, the default is PHPSESSID.

Session.save_path defines the parameters that are passed to the storage processor.

If the default files file processor is selected, this value is the path to the file that was created. The default is/tmp.

An optional n parameter to determine the directory depth of the session file distribution.

To use the n parameter, these directories must be created before use. In the Ext/session directory there is a small shell script called mod_files.sh that can be used to do this.

If the n parameter is used and n is greater than 0, automatic garbage collection will not be performed.

Session.save_handler defines the name of the processor that stores and obtains the data associated with the session. The default is files.

If the user has customized the storage, the value is changed to user.

Ini_set (' Session.save_handler ', ' user ');//This setting takes effect only for the current script.

SESSION.AUTO_START Specifies whether the session module starts a session automatically when the request starts. The default is 0 (does not start).

Session.gc_probability and Session.gc_divisor together define the probability of starting the GC (garbage collection garbage collection) process at each session initialization. This probability is calculated by Gc_probability/gc_divisor. For example, 1/100 means that there is a 1% probability of starting the GC process in each request. Session.gc_divisor defaults to 100. session.gc_probability defaults to 1.

/* "Picture generation and processing" */

GD Library//Canvas generation

# New Canvas

Imagecreate Creating a new palette-based image

Resource imagecreate (int $x _size, int $y _size)

Imagecreatetruecolor Create a new true color image

# Create a canvas based on an existing file or URL

Imagecreatefromgd2 creating a new image from a GD2 file or URL

Imagecreatefromgd2part Create a new image from a given GD2 file or part of a URL

IMAGECREATEFROMGD creating a new image from a gd file or URL

Imagecreatefromgif creating a new image from a file or URL

Imagecreatefromjpeg creating a new image from a file or URL

Imagecreatefrompng creating a new image from a file or URL

Imagecreatefromstring creating a new image from an image stream in a string

Imagecreatefromwbmp creating a new image from a file or URL

IMAGECREATEFROMXBM creating a new image from a file or URL

IMAGECREATEFROMXPM Create a new image//color assignment from a file or URL imagecolorallocate assign a color to an image

int Imagecolorallocate (resource $image, int $red, int $green, int $blue)

Imagecolorallocatealpha assigning color + alpha to an image

Imagecolordeallocate canceling the assignment of image colors

Imagecolortransparent to define a color as a transparent color

Imagecolorat Gets the color index value of a pixel

Imagecolorclosest gets the index value of the color closest to the specified color

Imagecolorclosestalpha gets the color that is closest to the specified color and transparency

IMAGECOLORCLOSESTHWB Gets the black-white index with the nearest chroma of the given color

Imagecolorexact gets the index value of the specified color

Imagecolorexactalpha the index value that gets the specified color plus transparency

Imagecolormatch the color of the palette version in an image to match the true color version

Imagecolorresolve gets the index value of the specified color or the nearest alternative value that is likely to be obtained

Imagecolorresolvealpha gets the index value of the specified color + alpha or the nearest alternative value that may be obtained

Imagecolorset set color for the specified palette index

Imagecolorsforindex get the color of an index

Imagecolorstotal gets the number of colors in the palette of an image//area fill Imagefill area fill

BOOL Imagefill (resource $image, int $x, int $y, int $color)

IMAGEFILLEDARC draw an elliptical arc and fill

Imagefilledellipse Draw an Ellipse and fill

Imagefilledpolygon draw a polygon and fill it

Imagefilledrectangle Draw a rectangle and fill

Imagefilltoborder area fills the bounds of the specified color

Imagesettile set map for fill//graphic Create IMAGEARC elliptical arc

Imagechar to draw a character horizontally

Imagecharup to draw a character vertically

Imagedashedline draw a dashed line

Imageellipse Draw an Ellipse

Imageline Drawing a line segment

Imagepolygon Draw a polygon

Imagerectangle Draw a rectangle

Imagesetpixel draw a single pixel

Imagesx Get Image width

Imagesy Get Image Height//Brush Settings Imagesetbrush Set brush image for line drawing

Imagesetstyle setting the style of line drawing

Imagesetthickness set the width of the drawing line//Graphic copy imagecopy part of the copy image

Imagecopymerge copy and merge part of an image

Imagecopymergegray copy and merge part of an image with grayscale

imagecopyresampled resampling and resizing copies of portions of images

Imagecopyresized copy part of the image and resize//character creation imagestring to draw a line of string horizontally

Imagestringup to draw a line of string vertically

Imagepsslantfont Tilt A font

Imagefontheight Get font height

Imagefontwidth Get font width

Imagettfbbox gets the range of text that uses TrueType fonts

Imageloadfont Loading a new font

Imagepsencodefont changing the character encoding vector in a font

Imagepsextendfont expand or refine the font//export canvas as Picture imagegif output the image to a browser or file in GIF format

Imagepng exporting images to a browser or file in PNG format

Imagejpeg exporting an image to a browser or file in JPEG format

Imagewbmp exporting an image to a browser or file in wbmp format

Sending the "content-type:image/picture format" via the header () allows the PHP script to output the image directly.

Header ("Content-type:image/gif"); Imagegif ($im);

IMAGEGD exporting GD images to a browser or file

IMAGEGD2 output the GD2 image to a browser or file//release canvas resource

Imagedestroy destroying images//image information

Image_type_to_extension get the file suffix of the image type getimagesize get the image size

Imagesx Get Image width

Imagesy Get Image Height

Imageistruecolor Check if the image is a true color image

Imagetypes returns the image types supported by the current PHP version//Image settings

Imagerotate rotating an image with a given angle

Imagealphablending to set the color blending mode of the image

Imageantialias whether to use anti-aliasing (antialias) function

ImageFilter using filters on images

Imagegammacorrect application of gamma correction to GD image

Imageinterlace Activate or disable interlaced scanning

/* "thumbnail" "watermark" */

imagecopyresampled resampling and resizing copies of portions of images

BOOL Imagecopyresampled (Resource $DST _image, Resource $src _image, int$dst_x, int $dst _y, int $src _x, int $src _y, I NT $DST _w, int $dst _h, int$src_w, int $src _h)

Imagecopymerge copy and merge part of an image

BOOL Imagecopymerge (Resource $DST _im, resource $src _im, int $dst _x, int $dst _y, int $src _x, int $src _y, int $src _w , int $src _h, int$pct) getimagesize get image size

Array getimagesize (string $filename [, Array & $imageinfo])

/* "URL function" */

Get_headers-gets the server to respond to all headers sent by an HTTP request get_meta_tags-extracts all META tag content properties from a file, returns an array http_build_query-generated Url-enco The de request string urldecode-decodes the encoded URL string urlencode-the encoded URL string parse_url-resolves the URL, returning its constituent parts

' Http://username:[email Protected]/path?arg=value#anchor '

Scheme (e.g. HTTP), host, port, user, pass, path, query (after the question mark?), fragment (after hash symbol #)

/encoding can be used to exchange multiple variables

$a = ' China '; $b = ' Sichuan '; $a = urlencode ($a); $b = UrlEncode ($b); $a = $a. ' & ' $b; $b = Explode (' & ', $a); $a = UrlDecode ($b [1] ); $b =urldecode ($b [0]); Echo $a, $b;//list () function for swapping variables list ($a, $b) = Array ($b, $a);

PHP most full note (v) (worth collecting, from time to times to look over)

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.