logo
Blog single photo

how to work session in php?


                        

<?php  
 $name ='dipankar'; 
 setcookie('myname',$name,time()+(86400*1)); 
 echo 'Hello '.($_COOKIE['myname']!='' ? $_COOKIE['myname'] : 'New'); 
 ?> 

example 2:- Session,
 <form method="POST" action=""> 
 <input type="test" name="name" value=""> 
 <input type="test" name="address" value=""> 
 <input type="test" name="phno" value=""> 
 <input type="submit" name="submit" value="save"> 
 </form> 

 <?php 
 if(isset($_POST['submit'])){ 
      $_SESSION['name']=$_POST['name']; 
      $_SESSION['address']=$_POST['address']; 
      $_SESSION['phno']=$_POST['phno']; 
      echo "<script type='text/javascript'>window.location.href = 'home.php';</script>"; 
 } 
 ?> 
 <!-- home.php --> 
 <?php 
 session_start();  
 if(!isset($_SESSION['name'])){ 
      header("Location :index.php"); 
 } 
 ?> 

 <p> Name: <?php echo $_SESSION['name']; ?> </p> 
 <p> Address: <?php echo $_SESSION['address']; ?> </p> 
 <p> Phone no: <?php echo $_SESSION['phno']; ?> </p> 

Top