PHP Getting Started session

Source: Internet
Author: User

This article is mainly for you to share a PHP introductory session of the method, with a good reference value, I hope to be helpful to everyone. Follow the small series together to see it.

Function: Store a user's information, change the user session settings, all pages can be used.

PHP Session variables

Open the program, make some changes, and then save the exit. is a session. The server can know who is operating through the session.
Working mechanism: Create a UID for the visitor, depending on the UID store variable, the UID is stored in a cookie, or URL conduction.

Using the PHP Session

Store user information before session, initiate a reply
Note: the Session_Start () function must precede the label:

<?php session_start ();  ? >

Register user sessions with the server to save user information while assigning a UID to a user session

Store Session variables

Storing and retrieving sessions is used$_SESSION

<?phpsession_start ()///Store session data if (Isset ($_session[' views '))} {    $_session[' views ']=$_session[' views ']+ 1;} else{    $_session[' views ']=9999;}? >

Output "Views: 9999"

Destroy Session

Which or function to use to unset() session_destroy() destroy

<?phpsession_start (); if (Isset ($_session[' views ')) {    //releases the specified SESSION variable    unset ($_session[' views ');} Complete destruction of Sessionsession_destroy ();? >

Related recommendations:

Session Principle and realization sharing

Session principle

How the session works in PHP

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.