Sat Jun 13 2020

Session

PHP Scripting940 views

File Name: php-session.php

<?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
Reference:

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.