Searching...
Thursday 11 October 2012

PHP : Cookies In Php

10:53 pm

Cookies In Php

Cookies In Php :

Cookies are two types :
1.      Temporary : are stored in the clients browser and gets deleted when the browser is closed.
2.      Permanent cookies :  are stored in client local system (in cookies folder) based on the expiration time specified in set cookie() function.
Loginform.php

<body bgcolor="marron" text="white"><h1 align="center">Indian Technologies </h1>
    <br><br><br>
    <form action="Loginform2.php" method="post">
        <table width="50%" align="right" style="font-family: verdana; font-size: 14px;background-color: #CCCCFF; color: black">
            <tr height="35">
                <?php
                echo "<td>UseName</td>";
                if(isset($_COOKIE['uid']))
                    echo "<td><input type=text name=t1 size=30 value=$_COOKIE[uid]></td></tr>";
                else
                  echo "<td><input type=text name=t1 size=30></td></tr>";
                echo "<tr height=35>";
                echo "<td> Pass Word</td>";
                echo "<td><input type=password name=t2 size=30></td></tr>";
                echo "<tr height=35>";
                echo "<td colspan=2 align=center><input type=submit value=Login></td></tr>";
                ?>
            </tr>
        </table>
    </form>
</body>

Loginform2.php

<?php
$s1 = $_REQUEST['t1'];
setcookie("uid",$s1,  time()+60*60*24*30);
echo "<h1> Welcome to Our site!!!";
?>

OutPut:

Welcome to Our site!!!
What is a browser does not support cookies ?
If your application deals with browsers that do not support cookie(in IE, tools > Internet options > privacy) , you will have to use other methods to pass information from one page to another in your application – we can use php session.

0 comments:

Post a Comment