Bagaimana cara mendaftarkan variabel dalam sesi PHP?

0
(0)

<?php

  

  session_start();

?>

<html>

<head>   

    <meta charset="utf-8">

    <meta name="viewport" content=

          "width=device-width, initial-scale=1">

    <link rel="stylesheet" href=

    <script src=

    </script>

    <script src=

    </script>

</head>

 

<body>

    <div class="container">

        <h2 style="color:green">GeeksforGeeks</h2>

        <strong>Session Manager</strong></br>

 

        <form method="POST">

            <br/>Enter Name: <input type="text" name="name"> <br />

            <br/>

            <div>

               <input type="submit" name="Submit1"

                       value="Create Session"

                       style="width:120;">

            </div><br/>

            <div>

              <input type="submit" name="Submit2"

                     value="Retrieve Session"

                     style="width:120;">

            </div>

            <div><br/>

               <input type="submit" name="Submit3"

                      value="Destroy Session"

                      style="width:120;">

            </div>

        </form>

    </div>

    <?php

 

    

    if(isset($_POST['Submit1']))

    

        $_SESSION["sname"]=$_POST["name"];

        echo "Session is created !!";

    }

     

    

    if(isset($_POST['Submit2']))

    

        if(isset($_SESSION["sname"]))

        {

            echo "The Session Value = " . $_SESSION["sname"];

        }

        else

        {

            

            

            

            echo "All Sessions Destroyed !!";

        }

    }

    if(isset($_POST['Submit3']))

    

        session_destroy();

    }

?>

 

</body>

</html>

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.