Çalışan sistem
index.php sayfamda giriş yoksa login.php gidiyor varsa ise index.php içeriği açılıyor.
Revizyon
Tek sayfa olsun index.php giriş yok ise login inputları görüksün
Giriş yapılınca aynı sayfada login ekranı gizlenip hoş geldin üye yazmak istiyorum.
Çalışan kodlar
index.php
<?php
include('inc/fonk.php'); // bagladım
session_start();
if (!(isset($_SESSION["Oturum"]) && $_SESSION["Oturum"] == "6789")) {
header("location:login.php");
}
?>
<h1> Hoş Geldin </h1>login.php<?php
session_start();
include("inc/fonk.php"); // bagladim
if (isset($_SESSION["Oturum"]) && $_SESSION["Oturum"] == "6789") {
header("location:index.php");
}
else if (isset($_COOKIE["cerez"])) {
$sorgu = $baglanti->prepare("select kullanici from kullanicilar");
$sorgu->execute();
while ($sonuc = $sorgu->fetch()) {
if ($_COOKIE["cerez"] == md5("aa" . $sonuc['kullanici'] . "bb")) {
$_SESSION["Oturum"] = "6789";
$_SESSION["kullanici"] = $sonuc['kullanici'];
header("location:index.php");
}
}
}
if ($_POST) {
$txtkullanici = $_POST["txtkullanici"];
$txtParola = $_POST["txtParola"];
}
?>
<form id="form1" method="post">
<input type="text" name="txtkullanici" value='<?php echo @$txtkullanici ?>' id="inputkullanici" class="form-control" placeholder="Kullanıcı Adı" required autofocus>
<input type="password" id="inputPassword" class="form-control" placeholder="Parola" required name="txtParola">
<label><input type="checkbox" ID="ckbHatirla" name="ckbHatirla"/>Beni hatırla</label>
<br>
<?php
if ($_POST) {
$sorgu = $baglanti->prepare("select parola from kullanicilar where kullanici=:kullanici");
$sorgu->execute(array('kullanici' => htmlspecialchars($txtkullanici)));
$sonuc = $sorgu->fetch();
if (md5("56" . $txtParola . "23") == $sonuc["parola"]) {
$_SESSION["Oturum"] = "6789";
$_SESSION["kullanici"] = $txtkullanici;
if (isset($_POST["ckbHatirla"])) {
setcookie("cerez", md5("aa" . $txtkullanici . "bb"), time() + (60 * 60 * 24 * 7));
}
header("location:index.php");
} else {
echo "Kullanıcı adı veya parola yanlış!";
}
}
?>
<input type="submit" class="btn btn-primary btn-block" ID="btnGiris" value="Giriş"/>
</form>Şimdiden Teşekkürler..