Cookies in PHP

Program 1

<html>
    <head><title>User Login Application for Cookies</title>
    <body>
<center>
   <form method=post action="testCookie2.php" >
    <table border=1>
        <tr>
            <th>User Name: </th>
            <td><input type=text name=txtuser></td>
        </tr>
        <tr>
            <th>Password: </th>
            <td><input type=password name=txtpass></td>
        </tr>
        <tr>
            <td></td>
            <td><input type=submit value=Submit name=submitbtn></td>
        </tr>
     <table>   
   </form>
</center>
</body>
</html>

Program 2

<html>
<body>
    <center>
        <h1>Test Cookie 2 Page</h2>
<pre>
  
<?php
   $user=$_POST['txtuser'];
   $pass=$_POST['txtpass'];
   echo "User Name: ".$user."<br>";
   echo "Password: ".$pass;

   $ckname="username";
   $ckvalue=$user;
   
   $ckname1="password";
   $ckvalue1=$pass;

   setcookie($ckname,$ckvalue,time()+3600,"/");
   setcookie($ckname1,$ckvalue1,time()+3600,"/");
   ?>
 </pre>

 <form method=post action="testCookie3.php" >
        <tr>
            <td></td>
            <td><input type=submit value=Submit name=submitbtn></td>
        </tr>
     <table>   
   </form>
</center>
</body>
</html>

Program 3

<html>
<body>
    <center>
    <h1>Test Cookie 3 Page</h2>
<pre>

<?php

   echo "User Name: ".$_COOKIE['username']."<br>";
   echo "User Name: ".$_COOKIE['password'];

   $ckemail="email";
   $ckemailvalue="[email protected]";
   setcookie($ckemail,$ckemailvalue,time()+3600,"/");
?>
</pre>
<form method=post action="testCookie4.php" >
        <tr>
            <td></td>
            <td><input type=submit value=Submit name=submitbtn></td>
        </tr>
     <table>   
   </form>
</center>
</body>
</html>

Program 4

<html>
<body>
    <center>
    <h1>Test Cookie 4 Page</h2>
<pre>

<?php

   echo "User Name: ".$_COOKIE['username']."<br>";
   echo "User Name: ".$_COOKIE['password']."<br>";
   echo "User Name: ".$_COOKIE['email']."<br>";
?>
</pre>
<form method=post action="testCookie4.php" >
        <tr>
            <td></td>
            <td><input type=submit value=Submit name=submitbtn></td>
        </tr>
     <table>   
   </form>
</center>
</body>
</html>
courses

TechVidvan Team

TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.

Leave a Reply

Your email address will not be published. Required fields are marked *