Home of web learners

www.webn3rd.com

PHP session is used to stored data in server and also in user storage as cookie

Session have the identifier to identify user

Application of session are like log in,log out user

If you want to work with session,you have to start session of those script or page you are working at the beginning

Its like creating a pipe or path

So,how to start,its simple

<?php
session_start();
?>

When you start session,you can now work with session

Now we need to work with session variable

Lets start an example:

<?php
session_start();
$_SESSION["username"] = "roy";
?>

Here,we see that we create a session variable which key is username,so we can use it anywhere in the webpage from the user where it is created.

So it stored in the server for this user

Lets use it

<?php
session_start();
echo $_SESSION["user"];
?>

output:

roy

So,this upper example are in another page,here you see we do not assign $_SESSION['user'] ,but we get the value,because in the previous example we already stored it in the server,so it comes from the server

webn3rd.com

About webn3rd