PHP in Hindi Sessions




PHP मे Sessions का उपयोग Server पर Information को Stored करने के लिए किया जाता है. Data एक Application मे सभी Pages पर उपलब्ध होता है एक Sessions कई Pages मे उपयोग की जाने वाली Information को रखने का एक Best तरीका है.

Session को आप एक Page से दूसरे Page पर Temporary रूप से Information को Stored और Pass करने के लिए उपयोग किया जाता है जब तक कि User Website को Close ना करे तब तक Cookie के द्वारा Information User के Computer मे Stored होती रहती है लेकिन Session की Information User के Computer पर Stored नहीं होती है.

Session प्रत्येक Visitors के लिए एक Unique Number बन कर और इस की Id के आधार पर Storage के लिए काम करता है. Session एक ही Webpage पर जाने के दौरान दो User के Data को एक दूसरे के साथ confused होने से रोकने में भी Help करता है.

PHP Session को शुरू करने के लिये session_start() function से Call करते है यह Function पहले Check करता है कि कोई Session पहले से शुरू हे कि नही अगर कोई पहले शुरू नही हुआ तो ये एक Session को शुरू कर देता है.

For Example

<?php
// PHP session start
session_start();
?>
<!DOCTYPE html>
<html>
   <head>
      <title>PHP session start</title>
   </head>
   <body>
      <?php  
        if($userid != '')
        {
            echo "User session is started.";
        }
        else
        {
            echo "User session is not started.";
        }
      ?>
   </body>
</html>

Output

User session is not started.

Destroy a PHP Session

सभी Global Session Variables को Remove करने और Session को Destroy करने के लिए session_unset () और session_destroy () का उपयोग करते है.

For Example

<?php
   session_start();
   
   if (isset($_SESSION['counter'])) {
      $_SESSION['counter']++;
   } else {
      $_SESSION['counter'] = 1; 
   }

   
   $msg = "You have visited this page ".  $_SESSION['counter'];
   $msg .= "in this session.";
   
   echo ( $msg );
?>

<p>
   To continue  click following link <br />
   
   <a  href = "nextpage.php?<?php echo htmlspecialchars(SID); ?>">
</p>

Output

You have visited this page 4in this session.
To continue click following link