Session (exp11)

Start_session.php 

<?php

// Start the session
session_start();
?>
<!DOCTYPE html>
<html>
<body>

<html>
    <head>
        <title>Login</title>
        <link rel="stylesheet" href="login.css">
    </head>
    <body>
        <div>
            <form action="login.php" method="post" >
           
            <label for="username">User Name:</label><br>
            <input type="text" id="username" name="username" placeholder="User Name.."><br>
           
            <label for="password">Password</label><br>
            <input type="password" id="password" name="passwd" placeholder="Password"><br>
           
            <input type="submit" name="login" value="LOGIN"><br><br>
            <a href="get_data.php">REGISTER</a>
            </form>
        </div>
    </body>
</html>


</body>
</html>






......................................................................................

#get_data.php
<!DOCTYPE html>
<html>
<body>

<?php
// define variables and set to empty values
$name = $email = $gender = $comment = $website = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  $name = test_input($_POST["name"]);
  $email = test_input($_POST["email"]);
  $password = test_input($_POST["password"]);
  $Adhaar = test_input($_POST["Adhaar"]);
  $gender = test_input($_POST["gender"]);
}

function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}
?>


    <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">

  Name: <input type="text" name="name">
  <br><br>
  E-mail: <input type="text" name="email">
  <br><br>
  Password: <input type="password" name="password">
  <br><br>
  Adhaar ID: <input type="number" name="Adhaar">
  <br><br>
  Gender:
  <input type="radio" name="gender" value="female">Female
  <input type="radio" name="gender" value="male">Male
  <input type="radio" name="gender" value="other">Other
  <br><br>
  <input type="submit" name="submit" value="Submit">  


<?php
session_start();

echo "<br><br><h2>Your Input:</h2>";
echo $name;
echo "<br>";
echo $email;
echo "<br>";
echo $gender;
echo "<br>"

?>

<a href="destroy_session.php">Log Out</a>

</body>
</html>

......................................................................................

#log_in.php
<?php
echo "First register your id";
?>

<html>
<br>
<a href="get_data.php">REGISTER</a>
</html>

......................................................................................
#destroy_session.php

<?php
session_start();
?>
<!DOCTYPE html>
<html>
<body>

<?php
// remove all session variables
//session_unset();

// destroy the session
session_destroy();
echo " You have succesfully logout";
?>

</body>
</html>


Post a Comment

0 Comments