1 / 6

PHP Session:How to start sessions in PHP

PHP Session provides the facility for storing the information which can be used across the webpages.

eitworld5
Download Presentation

PHP Session:How to start sessions in PHP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PHP Session: PHP Session provides the facility for storing the information which can be used across the webpages. Session In PHP is that if you log in some site and spend some time on it and after some time you logged out from site then time duration from login and logout is nothing but it is a session. In PHP you can start a session by using the session_start() function and can use the session for storing the information in the session variables using $_SESSION[“variableName”]; How to start PHP sessions: session_start() is used to start the PHP session. Here is the example of session in php is as follows: <?php // Start the session session_start(); ?> <!DOCTYPE html> <html> <body> <?php // Set session variables $_SESSION["user"] = "king"; $_SESSION["pass"] = "123"; echo "Session are set."; ?> </body> </html>

  2. The output is as follows: How to get PHP session values: You can get all the session values on any php page. The following example shows you the demo: <?php session_start(); ?> <!DOCTYPE html> <html> <body> <?php // Echo session variables that were set on previous page echo "user name is : " . $_SESSION["user"] . ".<br>"; echo "password is : " . $_SESSION["pass"] . ".";

  3. ?> </body> </html> The output is as follows: Another way to display session value: Print_r($_SESSION); is used to print all the session variable values. The example of this is as follows: <?php session_start(); ?> <!DOCTYPE html> <html> <body>

  4. <?php print_r($_SESSION); ?> </body> </html> The output is as follows: Modify the session variable values: You can change the value for session variables. The example to change the session variables are as follows: <?php session_start(); ?> <!DOCTYPE html> <html>

  5. <body> <?php // to change a session variable $_SESSION["user"] = "varshney"; print_r($_SESSION); ?> </body> </html> Here we have changed the user session value. Now output is as follows: How to destroy the session: Session_unset() function used for removing session variables and session_destroy() is used to remove the session. The example shows you how to remove the session:

  6. <?php session_start(); ?> <!DOCTYPE html> <html> <body> <?php // it remove all session variables session_unset(); // it destroy the session session_destroy(); ?> </body> </html> For more information visit: https://www.bebee.com/producer/@eit-world/php- session-how-to-start-sessions-in-php

More Related