mukeshdak

2025-09-29_creating a session in php

Sep 28th, 2025
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.38 KB | None | 0 0
  1. // check if php session has started
  2. // 1. first and best method
  3. if(session_id() == '') session_start();
  4. // if session is not started, session id will be empty.
  5.  
  6. // 2. second method
  7. if(!isset($_SESSION)) session_start();
  8. // if session is not set it should be started.
  9.  
  10. // 3. Third method
  11. if( !defined( 'SID' ) ) session_start();
  12. // start session if session id is not defined.
Tags: session
Advertisement
Add Comment
Please, Sign In to add comment