php

PHP is a general-purpose open-source scripting language that embeds programs into HTML documents for execution.

Embed PHP

  1. 1. XML style  
    <?php ……?>

     

  2. 2. Short style 
    <?……?>

     

  3. 3.SCRIPT style
      <script language="php">……</script>

     

  4. 4. ASP style 
    <%……%>

    *Style 2 and style 4 respectively need to set short_opern_tag and asp_tags as on in the php.ini configuration file.

type of data

PHP is a weakly typed programming language with 8 data types, boolean type boolean, integer type integer, floating point type float, string string, array type array, object type object, resource resource, NULL.

constant

define (name,value[, case_insensitive]);
 define (P,3.14159); // Assign 3.14159 to constant P
System Predefined Constants Function
_FILE_ The full path and filename of the file
_LINE_ current line number
_CLASS_ class name
_METHOD_ class method name
PHP_VERSION PHP version
PHP_OS The operating system on which the PHP program runs
DIRECTORY_SEPARATOR Returns the operating system separator
true logically true
false logical false
NULL a null value
E_ERROR Recent mistakes
E_WARNING The latest warning
E_PARSE Where parsing grammars are potentially problematic
E_NOTICE Where unusual hints occur, but not necessarily where errors occur

 variable

The character $ is added before the variable, the first letter of the variable name is a letter or an underscore, followed by a letter or an underscore or a number.

Use the . character as the concatenation operator in php

PHP supports the error control character @, which is placed before a PHP expression and any error messages that may be generated by the expression are ignored.

 PHP accesses the name attribute of the object variable s through ->: $s->name

Cookie

A cookie is a way that a server or script can maintain client information under HTTP. A cookie is a small text file saved by a web server on a user's browser, through which it can contain information about the user, and is often used to save user names, passwords, personalized settings, and personal preference records.

When a customer visits a website based on PHP technology, the setcookie() function can be used to generate a cookie in PHP, and the system will send the cookie to the client after processing and save it in C:\Documents and Settings\username\ under the Cookies directory.

  1. create cookie
    setcookie(name,value,expire,path,domain,secure)
    setcookie("testCookie","Hello",time()+3600);

    name and value respectively specify the name and value of the cookie, and are required parameters.

    expire specifies the validity period, path specifies the server path of the cookie, domain specifies the domain name of the cookie, and secure specifies whether to transmit the cookie through a secure HTTPS connection.
  2. access cookies
    /* Access cookies through the $_COOKIE variable */ 
    setcookie ("mycookieone","xyq" );
     echo  $_COOKIE ["mycookieone"];

     

  3. delete cookies
/* Method 1, call setcookie() with only name parameter and value parameter value as empty string */ 
setcookie ("delcookie","hello" );
 setcookie ("delcookie","" );
 /* Method 2 , make the expiration time time() or time-1 */ 
setcookie ("delcookie","hello", time ()+3600 );
 setcookie ("delcookie","", time ()-3600);

Session

Session is to leave user parameters on the server side. Session starts from the user accessing the page and ends the connection with the website, forming a session life cycle. During the session, assign a unique SessionID to the client to identify the current user and distinguish it from other users.

session_start(): Start a session or return an existing session.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324912343&siteId=291194637
php