Tags
Asked 3 years ago
17 Jun 2021
Views 195
Luigi

Luigi posted

How can I get session id in php and show it?

How can I get session id in php and show it?
steave

steave
answered Apr 27 '23 00:00

You can get the session ID in PHP using the session_id() function. To display the session ID on a web page, you can echo the result of session_id().

Here's an example:



// Start the session
session_start();

// Get the session ID
$session_id = session_id();

// Display the session ID
echo "Session ID: " . $session_id;

In this example, session_start() starts the session, and session_ id() returns the current session ID , which is assigned to the $session_id variable. The session ID is then displayed on the web page using echo.

Note that you need to call session_start() at the beginning of your PHP script to initialize the session and make th e $_SESSION superglobal array and session_id() function available.
Post Answer