Before getting a session id you need to start a session and that is done by using:
session_start() function.
Now that you have started a session you can get a session id by using:
session_id().
/* A small piece of code for setting, displaying and destroying session in PHP */