Session in PHP: Creating, Destroying, and Working With Session in PHP | Demo




#session php

How to Start a PHP Session?

You can start a session in PHP by using the session_start() function. This function will, by default, first check for an existing session. If a session already exists, it will do nothing, but it will create one if there’s no pre-existing session available


<?php

   session_start();

   if( isset( $_SESSION['counter'] ) ) {

      $_SESSION['counter'] += 1;

   }else {

      $_SESSION['counter'] = 1;

   }

   $count= "This page is visited ".  $_SESSION['counter'];

   $count.= " time during this session.";

?>

<html>

   <head>

      <title>Starting a PHP session</title>

   </head>

   <body>

      <?php  echo ( $count); ?>

   </body>

</html>


How to Destroy a Session in PHP?

Example: Using unset() to Destroy a Session Variable

<?php

    unset($_SESSION[‘counter’]);

?>

No comments:

Post a Comment

CPU vs GPU Architecture

  CPU vs GPU Architecture CPU (Central Processing Unit) and GPU (Graphics Processing Unit) have distinct architectural differences, optimize...

Best for you