A session is an interaction between a server and a browser. It is a data structure on the server that stores information about a user's visit. This topic provides a test sample and describes how to verify that the session feature of Cloud Web Hosting works correctly.
How sessions work
When you access a server from a browser, the server can start a session to store information about your visit, such as logon and operation details. The server then assigns a unique SessionID to your session. This SessionID links the browser to the server. If you visit other pages on the server before you close your browser, the server uses the SessionID to identify that the new requests are from the same user.
The server stores session information for a limited time. This information is destroyed after you close the web page.
Procedure
This topic applies only to Cloud Web Hosting instances that run the Linux operating system. Before you begin, make sure that you have a File Transfer Protocol (FTP) client installed. For example, you can download and install FileZilla.
Open a code editor, such as EditPlus. Copy the following sample code and save it as a session.php file.
NoteYou can use any code editor that you prefer.
Sample code to enable the session feature and store the views variable:
<?php session_start(); // Enable the session feature. if(isset($_SESSION['views'])) // Create a simple counter and call the isset() function to check if the views variable is set. $_SESSION['views']=$_SESSION['views']+1; // If the views variable is set, increment the counter. else $_SESSION['views']=1; // If the views variable is not set, create it and set its value to 1. echo "Views=". $_SESSION['views']; ?>Use FileZilla to upload the session.php file from your local host to the site's root directory /htdocs.
For more information, see Manage website program files using FileZilla.
In a browser, access
http://your-domain-name/session.phpfor the first time. The page displays the following content:Views=1Refresh the browser page. The page displays the following content:
Views=2NoteEach time you refresh the page, the value of Views increases by 1.
Modify the session.php file on your local host with the following sample code. Save the file and upload it again to the site's root directory
/htdocs.NoteYou can skip this step if you do not want to log off while browsing the web page, or if you want to wait for the session to time out (for example, after the default 20 minutes) and be automatically unregistered by the server.
The following is sample code for logging off a session:
<?php session_start(); // Enable the session feature. if(isset($_SESSION['views'])) // Create a simple counter and call the isset() function to check if the views variable is set. $_SESSION['views']=$_SESSION['views']+1; // If the views variable is set, increment the counter. else $_SESSION['views']=1; // If the views variable is not set, create it and set its value to 1. echo "Views=". $_SESSION['views']; session_destroy(); // Unregister the session feature. ?>In a browser, access
http://your-domain-name/session.php.No matter how many times you refresh the page, the value of Views remains 1. The page displays the following content:
Views=1If your test results match the description in the preceding steps, the session feature is working correctly. If your test results do not match, submit a ticket for assistance.