PHP bir log-out köprü?

7 Cevap

Durumda birileri nasıl PHP bir köprü yapabilir, bilir ...

<?php
  echo( '<a href="index.php">Log-out</a>' );
?> 

değil sadece cekti ilk sayfaya gitmek için değil, aynı zamanda çerezleri kaldırmak?

Teşekkürler!

7 Cevap

index.php?logout=true gibi bağlantı içinde bir parametreyi göndermek sizin index.php bu parametre kontrol ve set ise, çerezleri silin:

http://php.net/manual/de/function.setcookie.php

Eğer geçmişte bir şey için bir çerez "ömür boyu" (sona) (veya tamamen dışarı bırakın) ayarlarsanız, bu (yardım bulmak için "php çerezi silmek" için bir Google araması yapmak) sonraki pageload kaldırılmış olacaktır. Gerekirse, bir sayfa yeniden kuvvet.

Ayrıca kullanıcının oturumu yok etmek isteyebilirsiniz.

Sen (yani geçmişte sona erecek onları ayarlar) ve daha sonra yönlendirir bütün çerezleri siler başka bir sayfa yapabilirsiniz index.php:

// page: clear.php
<?php
session_start();
$_SESSION = array();
session_destroy();

setcookie('cookie1', '', strtotime('-2 days'));
setcookie('cookie2', '', strtotime('-2 days'));
// etc.
header('Location: index.php');
exit();

Ben genellikle tarafından reçete yöntemi kullanmak manual:

<?php
// Initialize the session.
// If you are using session_name("something"), don't forget it now!
session_start();

// Unset all of the session variables.
$_SESSION = array();

// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (ini_get("session.use_cookies")) {
    $params = session_get_cookie_params();
    setcookie(session_name(), '', time() - 42000,
        $params["path"], $params["domain"],
        $params["secure"], $params["httponly"]
    );
}

// Finally, destroy the session.
session_destroy();
?>

Geriye kalan tek şey, header('Location: index.php');

Böyle bağlantıyı kullanabilirsiniz:

<?php
  echo( '<a href="index.php?link=logout">Log-out</a>' );
?> 

Ve index.php:

<?php
  $link = $_GET["link"];
  if($link == "logout")
  {
     session_destroy();
  }
?>

Navigasyon menüsünde:

<a href="logout.php">Log out</a>

In logout.php,

<?php
// kill the session
header('Location: index.php');
exit();    

Oturumu öldürmek için, PHP kılavuzda session_destroy() de bir örneğini görüyoruz.

İşte HTML link

<a href="index.php?logout">Log-out</a>

Ve PHP çıkıyor için işlemek için

if(isset($_GET['logout'])) {
    // clear the session variable, display logged out message
}

Kapatma Bağlantısı:

<a href="logout.php">Log Out</a>

logout.php

<?php
    session_start();
    session_destroy();
?>