5 Ağustos 2016 Cuma

Php'de Session Oturum Kapatma ve Oturum Süresi Verme

//session oturum kapatma ve oturum süresi verme
//index.php
<?php

$kullanici=$_COOKIE["kullanici"];

if($kullanici!=""){
    header("location:giris.php");
   
   
}else{
   
    echo '<form action="giris.php" method="post">
    Kullanıcı: <input type="kullanici" name="kullanici"/>
    <input type="submit" value="Giris"/>
   
</form>';
}

?>

//giris.php
<?php
//ilk php taglarının hemen altına bu satırları(session) açıyoruz.
ob_start();
session_start();

$kullanici=$_COOKIE["kullanici"];
if($kullanici==""){
    $kullanici=$_POST["kullanici"];
    setcookie("kullanici",$kullanici,time()+24*60*60);
   
    $_SESSION["kullanici"]=$_COOKIE["kullanici"];
    header("location:hesabiniz.php");
   
   
}else{
    $_SESSION["kullanici"]=$kullanici;
      header("location:hesabiniz.php");
   
}
?>
//hesabiniz.php
<?php
session_start();//burayada session_start() yazıyoruz.
$kullanici=$_SESSION["kullanici"];
if($kullanici==""){
    echo "Bu sayfayı görüntüleme için üye girişi yapın";
   
   
}else{
    echo "Üye girişi yaptınız<br>Kullanıcı adınız: ".$kullanici."<br>";
    echo "<a href='cikis.php'>Oturumu Kapat</a>";
   
}

?>
//cikis.php
<?php
session_start();//session_start() yazıyoruz.


$kullanici=$_SESSION["kullanici"];
session_destroy();//sessionı yoketmek için
setcookie("kullanici","",time()-1);
header("location:index.php");


?>

Hiç yorum yok:

Yorum Gönder