<p id="xv90w"><pre id="xv90w"></pre></p>
    <ul id="xv90w"><video id="xv90w"></video></ul>
    <li id="xv90w"><listing id="xv90w"></listing></li>
    <abbr id="xv90w"><tfoot id="xv90w"></tfoot></abbr>

    <\/body>\n <\/html> <\/pre>\n\n

    Note:
    \n<\/p>\n

    (1) The session_start() function must be located before the tag, that is, the function must be called before any output. Often when writing a program, an extra space or carriage return is accidentally entered. In this case, An error will be reported. Special attention should be paid to this. (I have been tricked)
    \n<\/p>\n

    (2) The session_start() function will return TRUE regardless of whether the session is successfully created, so using any exception handling will not work.
    \n<\/p>\n

    (3) You can also enable the configuration instruction session.auto_start so that you do not have to execute this function, but in this case, a session will be started or continued when each php page is executed.
    \n<\/p>\n

    2. Store or read session <\/strong>
    \n<\/p>\n

    The correct way to store and read session variables is to use PHP's S ESSION variable. SESSION variable. _SESSION is a global parameter provided by PHP and is specially used to store and read sessions. (Note that the key names of associative arrays are consistent with the naming rules of ordinary variables)
    \n<\/p>\n

    When storing a session, you can assign it directly.
    \n<\/p>\n

    $_SESSION['season'] = 'Autumn';
    \n<\/p>\n

    The above sets a session element with the key name \"season\" and its value is \"autumn\". When reading, it is just like calling a normal array element.
    \n<\/p>\n

    The following two code snippets show how to store and read a session element.
    \n<\/p>\n

    This is the session1.php file:
    \n<\/p>\n\n

    \n <?php\n \/**\n  * Created by PhpStorm.\n  * User: yuxiu\n  * Date: \/\/\n  * Time: :\n  *\/\n if(isset($_POST['submit'])){\n   session_start();                \/\/開始建立一個會話\n   $_SESSION['season'] = $_POST['season'];    \/\/存儲會話數(shù)據(jù)\n   header(\"Location: session.php\");      \/\/應特別注意header()里的格式問題\n }\n ?>\n 存儲會話<\/b>\n \n 選擇需要設置的數(shù)據(jù):\n 
    \n \n <\/form><\/pre>\n\n

    This is the session2.php file:
    \n<\/p>\n

    <\/p>\n\n

    \n <?php\n \/**\n  * Created by PhpStorm.\n  * User: yuxiu\n  * Date: \/\/\n  * Time: :\n  *\/\n session_start();  \/\/建立或者繼續(xù)一個會話\n $season = $_SESSION['season'];    \/\/讀取會話數(shù)據(jù)\n echo \"讀取會話<\/b>\";\n switch ($season) {\n   case '春天';\n     echo '現(xiàn)在是綠意盎然的春天!';\n     break;\n   case '夏天';\n     echo '現(xiàn)在是熱情四溢的夏天!';\n     break;\n   case '秋天';\n     echo '現(xiàn)在是豐收果實的秋天!';\n     break;\n   case '冬天';\n     echo '現(xiàn)在是白雪皚皚的冬天!';\n     break;\n   default ;\n     echo '對不起,會話中沒有數(shù)據(jù) 或者 不存在該對話 !';\n }\n ?><\/pre>\n\n

    In session1.php, first use session_start() to create a session, then use array assignment to store the submitted seasonal data, and finally use the header() function to jump directly to the beginning. In the session2.php file, the session_start() function is also needed to continue a session and use the session array to call session information.
    \n<\/p>\n

    3. Destroy session <\/strong>
    \n<\/p>\n

    When the session is no longer used, it needs to be destroyed manually. Although PHP has the function of automatically destroying the session, this will make the program less efficient. You can use the unset() function or session_destroy() function.
    \n<\/p>\n\n

    \n<?php\n unset($_SESSION['season']);\n?><\/pre>\n\n

    Or:
    \n<\/p>\n\n

    \n<?php\n session_destroy();   \/\/注意,使用這個函數(shù)將重置session數(shù)組,即失去所有的已經(jīng)儲存的session數(shù)據(jù)\n?><\/pre>\n

    <\/p>\n

    \nhttp:\/\/www.bkjia.com\/PHPjc\/1133847.html<\/span>www.bkjia.com<\/span>true<\/span>http: \/\/www.bkjia.com\/PHPjc\/1133847.html<\/span>TechArticle<\/span>PHP session session processing function, session session PHP Session variable When running an application, you will open it, do make some changes and then close it. It's a lot like a session. Computer...<\/span>\n<\/div>\n
    <\/div>"}

    国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

    Table of Contents
    PHP session session processing function, session session
    Home Backend Development PHP Tutorial PHP session session processing function, session session_PHP tutorial

    PHP session session processing function, session session_PHP tutorial

    Jul 12, 2016 am 08:50 AM
    php session function

    PHP session session processing function, session session

    PHP Session variable

    When you run an application, you open it, make changes, and then close it. It's a lot like a session. The computer knows who you are. It knows when you start the application and when it terminates it. But on the Internet, there's a problem: the server doesn't know who you are and what you do, and that's because HTTP addresses don't maintain state.

    PHP session solves this problem by storing user information on the server for subsequent use (such as user name, purchased items, etc.). However, session information is temporary and will be deleted after the user leaves the site. If you need to store information permanently, you can store the data in a database.

    Session works by creating a unique id (UID) for each visitor and storing variables based on this UID. The UID is stored in a cookie or passed through the URL.

    1. Start conversation

    Before saving information to the session, you must first open the session. PHP provides the session_start() function to start or continue a session. Definition:

    1 bool session_start( void )

    The call is as follows:

    <&#63;php session_start();&#63;>
     <html>
     <body></body>
     </html> 

    Note:

    (1) The session_start() function must be located before the tag, that is, the function must be called before any output. Often when writing a program, an extra space or carriage return is accidentally entered. In this case, An error will be reported. Special attention should be paid to this. (I have been tricked)

    (2) The session_start() function will return TRUE regardless of whether the session is successfully created, so using any exception handling will not work.

    (3) You can also enable the configuration instruction session.auto_start so that you do not have to execute this function, but in this case, a session will be started or continued when each php page is executed.

    2. Store or read session

    The correct way to store and read session variables is to use PHP's S ESSION variable. SESSION variable. _SESSION is a global parameter provided by PHP and is specially used to store and read sessions. (Note that the key names of associative arrays are consistent with the naming rules of ordinary variables)

    When storing a session, you can assign it directly.

    $_SESSION['season'] = 'Autumn';

    The above sets a session element with the key name "season" and its value is "autumn". When reading, it is just like calling a normal array element.

    The following two code snippets show how to store and read a session element.

    This is the session1.php file:

     <&#63;php
     /**
      * Created by PhpStorm.
      * User: yuxiu
      * Date: //
      * Time: :
      */
     if(isset($_POST['submit'])){
       session_start();                //開始建立一個會話
       $_SESSION['season'] = $_POST['season'];    //存儲會話數(shù)據(jù)
       header("Location: session.php");      //應特別注意header()里的格式問題
     }
     &#63;>
     <b>存儲會話</b>
     <hr/>
     選擇需要設置的數(shù)據(jù):
     <form name="form" method="post" action="" id="form" >
       <select name="season" id="season_select" >
         <option value="春天">春天</option>
         <option value="夏天">夏天</option>
         <option value="秋天">秋天</option>
         <option value="冬天">冬天</option>
       </select>
       <br/>
       <br/>
       <br/>
      <input type="submit" name="submit" value="submit"/>
     </form>

    This is the session2.php file:

     <&#63;php
     /**
      * Created by PhpStorm.
      * User: yuxiu
      * Date: //
      * Time: :
      */
     session_start();  //建立或者繼續(xù)一個會話
     $season = $_SESSION['season'];    //讀取會話數(shù)據(jù)
     echo "<b>讀取會話</b><br/><br/>";
     switch ($season) {
       case '春天';
         echo '現(xiàn)在是綠意盎然的春天!';
         break;
       case '夏天';
         echo '現(xiàn)在是熱情四溢的夏天!';
         break;
       case '秋天';
         echo '現(xiàn)在是豐收果實的秋天!';
         break;
       case '冬天';
         echo '現(xiàn)在是白雪皚皚的冬天!';
         break;
       default ;
         echo '對不起,會話中沒有數(shù)據(jù) 或者 不存在該對話 !';
     }
     &#63;>

    In session1.php, first use session_start() to create a session, then use array assignment to store the submitted seasonal data, and finally use the header() function to jump directly to the beginning. In the session2.php file, the session_start() function is also needed to continue a session and use the session array to call session information.

    3. Destroy session

    When the session is no longer used, it needs to be destroyed manually. Although PHP has the function of automatically destroying the session, this will make the program less efficient. You can use the unset() function or session_destroy() function.

    <&#63;php
     unset($_SESSION['season']);
    &#63;>

    Or:

    <&#63;php
     session_destroy();   //注意,使用這個函數(shù)將重置session數(shù)組,即失去所有的已經(jīng)儲存的session數(shù)據(jù)
    &#63;>

    www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1133847.htmlTechArticlePHP session session processing function, session session PHP Session variable When running an application, you will open it, do make some changes and then close it. It's a lot like a session. Computer...
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    Why We Comment: A PHP Guide Why We Comment: A PHP Guide Jul 15, 2025 am 02:48 AM

    PHPhasthreecommentstyles://,#forsingle-lineand/.../formulti-line.Usecommentstoexplainwhycodeexists,notwhatitdoes.MarkTODO/FIXMEitemsanddisablecodetemporarilyduringdebugging.Avoidover-commentingsimplelogic.Writeconcise,grammaticallycorrectcommentsandu

    How to Install PHP on Windows How to Install PHP on Windows Jul 15, 2025 am 02:46 AM

    The key steps to install PHP on Windows include: 1. Download the appropriate PHP version and decompress it. It is recommended to use ThreadSafe version with Apache or NonThreadSafe version with Nginx; 2. Configure the php.ini file and rename php.ini-development or php.ini-production to php.ini; 3. Add the PHP path to the system environment variable Path for command line use; 4. Test whether PHP is installed successfully, execute php-v through the command line and run the built-in server to test the parsing capabilities; 5. If you use Apache, you need to configure P in httpd.conf

    PHP Syntax: The Basics PHP Syntax: The Basics Jul 15, 2025 am 02:46 AM

    The basic syntax of PHP includes four key points: 1. The PHP tag must be ended, and the use of complete tags is recommended; 2. Echo and print are commonly used for output content, among which echo supports multiple parameters and is more efficient; 3. The annotation methods include //, # and //, to improve code readability; 4. Each statement must end with a semicolon, and spaces and line breaks do not affect execution but affect readability. Mastering these basic rules can help write clear and stable PHP code.

    Your First PHP Script: A Practical Introduction Your First PHP Script: A Practical Introduction Jul 16, 2025 am 03:42 AM

    How to start writing your first PHP script? First, set up the local development environment, install XAMPP/MAMP/LAMP, and use a text editor to understand the server's running principle. Secondly, create a file called hello.php, enter the basic code and run the test. Third, learn to use PHP and HTML to achieve dynamic content output. Finally, pay attention to common errors such as missing semicolons, citation issues, and file extension errors, and enable error reports for debugging.

    What is PHP and What is it Used For? What is PHP and What is it Used For? Jul 16, 2025 am 03:45 AM

    PHPisaserver-sidescriptinglanguageusedforwebdevelopment,especiallyfordynamicwebsitesandCMSplatformslikeWordPress.Itrunsontheserver,processesdata,interactswithdatabases,andsendsHTMLtobrowsers.Commonusesincludeuserauthentication,e-commerceplatforms,for

    PHP 8 Installation Guide PHP 8 Installation Guide Jul 16, 2025 am 03:41 AM

    The steps to install PHP8 on Ubuntu are: 1. Update the software package list; 2. Install PHP8 and basic components; 3. Check the version to confirm that the installation is successful; 4. Install additional modules as needed. Windows users can download and decompress the ZIP package, then modify the configuration file, enable extensions, and add the path to environment variables. macOS users recommend using Homebrew to install, and perform steps such as adding tap, installing PHP8, setting the default version and verifying the version. Although the installation methods are different under different systems, the process is clear, so you can choose the right method according to the purpose.

    How Do You Handle File Operations (Reading/Writing) in PHP? How Do You Handle File Operations (Reading/Writing) in PHP? Jul 16, 2025 am 03:48 AM

    TohandlefileoperationsinPHP,useappropriatefunctionsandmodes.1.Toreadafile,usefile_get_contents()forsmallfilesorfgets()inaloopforline-by-lineprocessing.2.Towritetoafile,usefile_put_contents()forsimplewritesorappendingwiththeFILE_APPENDflag,orfwrite()w

    python if else example python if else example Jul 15, 2025 am 02:55 AM

    The key to writing Python's ifelse statements is to understand the logical structure and details. 1. The infrastructure is to execute a piece of code if conditions are established, otherwise the else part is executed, else is optional; 2. Multi-condition judgment is implemented with elif, and it is executed sequentially and stopped once it is met; 3. Nested if is used for further subdivision judgment, it is recommended not to exceed two layers; 4. A ternary expression can be used to replace simple ifelse in a simple scenario. Only by paying attention to indentation, conditional order and logical integrity can we write clear and stable judgment codes.

    See all articles