PHP site bazen işler için giriş yapın

0 Cevap php

Benim giriş sistemi ile ilgili bir sorun yaşıyorum. Bazen, bazen öyle değil, çalışır. Bu daha sık ilk denemede başarısız olur ve dolaşmak ikinci çalışır gibi görünüyor. HAYIR HATA yoktur; bu gerekiyordu ama oturum değişkenleri boş geliyor gibi sayfa ana sayfasına yönlendirir.

Bir kullanıcı adı / pass kabul edildikten sonra ilk kod bloğu ilgili giriş yazısıdır. İkinci blok i oturumu vars ana sayfasını ayarlamak arn't kullanıcı herhangi bir tanımlama olup olmadığını görmek için ne kullanın. Üçüncü saat benim çıkış yazısıdır.

Şimdiden teşekkürler.

// The log-in is OK so set the user ID and username session vars (and cookies), and redirect to the home page
$row = mysqli_fetch_array($data);
$_SESSION['user_id'] = $row['user_id'];
$_SESSION['username'] = $row['username'];
$_SESSION['first_name'] = $row['first_name'];

if($rememberme == 1)
{    
    setcookie('user_id', $row['user_id'], time() + (60 * 60 * 24 * 30));    // expires in 30 days
    setcookie('username', $row['username'], time() + (60 * 60 * 24 * 30));  // expires in 30 days
    setcookie('first_name', $row['first_name'], time() + (60 * 60 * 24 * 30));  // expires in 30 days
}

if($ref==0)
{
    header("location: http://domain.com/test.php");

}
else
{
    header("location: http://domain.com/".$ref);

}

İkinci blok:

session_start();

if (!isset($_SESSION['user_id'])) {

    if (isset($_COOKIE['user_id']) && isset($_COOKIE['username']) && isset($_COOKIE['first_name'])) {
        $_SESSION['user_id'] = $_COOKIE['user_id'];
        $_SESSION['username'] = $_COOKIE['username'];
        $_SESSION['first_name'] = $_COOKIE['first_name'];
    }
}

Üçüncü blok:

// If the user is logged in, delete the session vars to log them out
session_start();
if (isset($_SESSION['user_id'])) 
{
    // Delete the session vars by clearing the $_SESSION array
    $_SESSION = array();

    // Delete the session cookie by setting its expiration to an hour ago (3600)
    if (isset($_COOKIE[session_name()])) 
    {
      setcookie(session_name(), '', time() - 3600);
    }

    // Destroy the session
    session_destroy();
}

// Delete the user ID and username cookies by setting their expirations to an hour ago (3600)
setcookie('user_id', '', time() - 3600);
setcookie('username', '', time() - 3600);

// Redirect to the home page
header('Location: http://domain.com/test.php');

0 Cevap