PRACTICAL NO. 17

                                                                             

PRACTICAL NO. 17

AIM: To create a PHP page for login page with SQL connection.

PROGRAM:

 Develop web page with data validation. √ Write simple PHP program to

a.      Set cookies and read it.

 

Code:

<?php

if (!isset($_COOKIE['visits'])) $_COOKIE['visits'] = 0;

$visits = $_COOKIE['visits'] + 1;

setcookie('visits',$visits,time()+3600*24*365);

?>

<html>

<head><style type="text/css">

div {font-size:20pt;color:navy;font-family:arial black; width:50%;background-color:white}

p

{font-size:18pt; color: lime; font-weight:bold; text-align:center; font-family:bauhus 93}

.groove{border-style:groove}

.dotted{border-style:dotted}

</style></head><body bgcolor="lightblue">

<?php

echo'<br><br><center><div class="groove">HIT COUNTER USING COOKIES</div><br>';

echo'<div class="dotted">';

if ($visits > 1)

 {

echo "<p>This is visit number $visits</p>";}

else

   {

    echo'<p>Welcome to my Website! Click here for a tour!</p>';

   }

echo"<br></center></div>";

?>

</body></html>











.      Demonstrate session management

Logout.php:

<?php

header('location:des.php');

?>

 

DES.php:

<?php

session_start();

if(@$_POST['submit1'])

{

$u = $_POST['text1'];

$p = $_POST['pwd'];

if($u =="nithyasuhana@gmail.com" && $p=="nithya@1986")

{

$_SESSION['luser'] = $u;

$_SESSION['start'] = time();

// taking now logged in time

$_SESSION['expire'] = $_SESSION['start'] + (1*60) ; 

// ending a session in 1 minutes from the starting time

header('Location: home.php');

}

else

{

$err= "<font color='red'>Invalid user login </font>";

}

}

?>

<html>

 <head>

  <title>Destroy Session after 1 minutes - Phptpoint.com</title>

 </head>

 <body>

 <form name="form1" method="post">

 <table align="center">

  <tr>

  <Td colspan="2"><?php echo @$err;?></Td>

 </tr> 

  <tr>

   <td>Username </td>

   <td><input type="email" name="text1"  placeholder="nithyasuhana@gmail.com"

required>

   </td>

  </tr>

  <tr>

   <td>Password</td>

   <td><input type="password" name="pwd" placeholder="nithya@1986" required></td>

  </tr>

 

<tr>

  <td colspan="2"  align="center">

   <input type="submit" value="SignIn" name="submit1">

   </td> </tr>

 </table>

</form>

 </body>

 </html>






Home.php:

<?php

 session_start();

 if(!isset($_SESSION['luser']))

 {

    echo "<p align='center'>Please Login again ";

  echo "<a href='des.php'>Click Here to Login</a></p>";

 }

 else

 {

    $now = time();

 // checking the time now when home page starts

    if($now > $_SESSION['expire'])

 

    {

 session_destroy();

       echo "<p align='center'>Your session has expire ! <a href='login.php'>Login Here</a></p>";

     }

}

?>

<html>

 <head>

  <title>Destroy Session after 1 minutes - Phptpoint.com</title>

 </head>

 <body>

<p style="background:#CCCCCC">

Welcome

<span style="float:right"><a href='logout.php'>LogOut</a></span>

<p style="padding-top:20px;background:#CCCCCC; height:400px; text-align:center">

<span style="color:red;text-align:center">Your Session Will destroy after 1 minutes You will  

redirected on next page</span>

<br/><br/>

<span>if you want to logout before 1minutes click on logout link </span>

</p>   

</p>

 

</body>

</html>








 

Comments

Popular posts from this blog

Practical No.1

Practical 8 ( Recursive Function. )