Tags
Asked 2 years ago
13 Jul 2021
Views 194
Hope

Hope posted

What is Session_start () in PHP ?

What is Session_start () in PHP ?
jaman

jaman
answered Aug 20 '21 00:00

session_start() function is used to start the session in PHP.
session_start() function is mostly called in the starting of the execution in the PHP . so all next execution have session variables available.

after starting the session with session_start() , developers can access the session value or set the session value through the $_SESSION .

for example:

session_start();
$_SESSION['data']=true;
echo($_SESSION['data']);
print_r($_SESSION);


above code start session with session_start() function and then you can assign value to the session by through $_SESSION array like this :
$_SESSION['data']=true;
so now the session has an index that has the value "true".
to access the session value, just use the index at $_SESSION array.
for example :
echo($_SESSION['data']);
and print_r($_SESSION) will print all session variable and their values. $_SESSION is array and all array features and function can be applied to $_SESSION .
Post Answer