PHP Scripting

Session

Learn PHP by example for session and its usability

6/13/2020
0 views
php-session.phpPHP
<?php

	/* Start Session */
	session_start();
   
	/* Set session variable with value */
	$_SESSION['username'] = "geek_user";
	$_SESSION['user_type'] = 1;

	/* Get session values */
	echo "Username: ".$_SESSION['username']."<br />";
	echo "User Type: ".$_SESSION['user_type']."<br />";
   
	/* set the cache expire to 30 minutes */
	session_cache_expire(30);
   
	/* Encode session variables */
	$session_vars = session_encode();
	echo "Session Encoded: ".$session_vars."<br />";
   
	/* Modify session variable's value */
	$_SESSION['username'] = "end_user";
	echo "Username: ".$_SESSION['username']."<br />";
   
	/* Unset session */
	unset($_SESSION['username']);
	unset($_SESSION['user_type']);
	
	/* Free all session variables */
	session_unset();
   
	/* Destroy session */
	session_destroy(); 	
?>



/* Output */
Username: geek_user
User Type: 1
Session Encoded: username|s:9:"geek_user";user_type|i:1;
Username:end_user
PHPsession in PHPPHP code

Loading comments...

Related Examples

Deliver breaking news, insightful commentary, and exclusive reports.

Targeting readers who rely on our platform to stay ahead of the curve.

Contact Us: benzingaheadlines@gmail.com