Use of session in php

<?php //Authentication using session() //short variables $username = $_POST['username'];//username is used in html(<input type="text" name="usename">) $passwd = $_POST['password'];//password is used in html(<input type="password" name="password">) //check_valid_user($username,$passwd) function check the user input is correct or not using mysql or other database in which we kept the data. if(check_valid_user($username,$passwd)) { session_start();//session start $_SESSION['valid_user'] = $username; //This session variable will be used for authenticate. } //For logout $old_user = $_SESSION['valid_user']; unset($_SESSION['valid_user']); session_destroy(); echo ("Logged out $old_user"); //To make the accessible $_SESSION['valid_user'] in other php scripts.We need only start the session by using session_start(). ?>
If we want to authenticate any person from one html page to another html page then it is very useful code in this scenario.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.