PHP session_name() Function

What is session_name Function?

Explanation

The "session_name()" function is used to get or set the current session name.

Syntax:


session_name(name)

In the above syntax, if the session name is specified using "name" it will set the session name, if not it will return the current session name.

Example :


<?php
session_start();
echo "<b>Session name using get:</b>", session_name();
session_name("MY_SESSION");
echo"<br>";
echo "<b>Session name using set:</b>", session_name();
?>
Result :

Session name using get:PHPSESSID
Session name using set:MY_SESSION

In the above example, first the current or default session name "PHPSESSID" is displayed then the name "MY_SESSION" which is set is displayed.

PHP Topics


Ask Questions

Ask Question