-
-
Save cem766/2654944e0623f06efb25 to your computer and use it in GitHub Desktop.
PHP PDO MYSQL SİMPLE LOGİN SYSTEM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // veri tabanı bağlantısı | |
$ip = "localhost"; //host | |
$user = "root"; // host id | |
$password = ""; // password local olduğu için varsayılan şifre boş | |
$db = "dbtest"; // db adı | |
//bağlantı | |
try{ | |
$db = new PDO("mysql:host=$ip;dbname=$db",$user,$password); | |
// türkçe karakter için utf8 | |
$db->exec("SET CHARSET UTF8"); | |
//eğer hata olursa pdo nun exception komutu ile ekrana yazdırıyoruz | |
}catch(PDOException $e){ | |
die ("Hata var"); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html lang="en-US"> | |
<head> | |
<meta charset="UTF-8"> | |
<title></title> | |
</head> | |
<body> | |
<!-- giriş yap--> | |
<form action="login.php" method="post"> | |
<input type="text" name="name"/> | |
<input type="password" name="pass"/> | |
<input type="submit" /> | |
</form> | |
üye değilseniz üye olmak için <a href="register.php">Tıklayın</a> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include ("conn.php"); | |
if($_POST) | |
{ | |
$name =$_POST["name"]; | |
$pass =$_POST["pass"]; | |
$query = $db->query("SELECT * FROM dbtest WHERE dbname='$name' && dbpassword='$pass'",PDO::FETCH_ASSOC); | |
if ( $say = $query -> rowCount() ){ | |
if( $say > 0 ){ | |
session_start(); | |
$_SESSION['oturum']=true; | |
$_SESSION['name']=$name; | |
$_SESSION['pass']=$pass; | |
print 'Hoş geldiniz '.$name; | |
echo ' | |
<a href="logout.php">çıkış yap</a> | |
'; | |
}else{ | |
echo "oturum açılmadı hata"; | |
} | |
}else{ | |
echo "<h1>Kullanıcı adı veya şifre hatalı</h1>"; | |
echo ' | |
<form action="giris_yap.php" method="post"> | |
<input type="text" name="name"/> | |
<input type="password" name="pass"/> | |
<input type="submit" /> | |
</form> | |
'; | |
} | |
}else{ | |
echo " <h1> lütfen giriş yapın</h1>"; | |
echo ' | |
<form action="giris_yap.php" method="post"> | |
<input type="text" name="name"/> | |
<input type="password" name="pass"/> | |
<input type="submit" /> | |
</form> | |
'; | |
echo 'üye değilseniz üye olmak için <a href="kayit.php">Tıklayın</a>'; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
session_destroy(); | |
session_unset(); | |
unset($_SESSION['oturum']); | |
header("Location:index.php"); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include ("conn.php"); | |
if($_POST){ | |
// Post ettirdik | |
$name = $_POST["name"]; | |
$password = $_POST["password"]; | |
//bütün kayıtları bir kereye mahsus olmak üzere listeliyoruz; daha doğrusu, bir diziye aktarmak için verileri çekiyoruz | |
$query = "SELECT * FROM dbtest order by id"; | |
$goster = $db->prepare($query); | |
$goster->execute(); //queriyi tetikliyor | |
$result = $db->prepare("INSERT INTO dbtest SET dbname=?,dbpassword=?"); | |
$result->execute(array($name,$password)); | |
}else{ | |
echo ' | |
<form action="" method="post"> | |
<label for="name">Name</label> | |
<input type="text" name="name" placeholder="Name"/> | |
<label for="password">Password</label> | |
<input type="password" name="password" placeholder="Password"/> | |
<input type="Submit" value="Giriş Yap"/> | |
</form> | |
'; | |
echo 'üye iseniz giriş yapmak için <a href="giris_yap.php">tıklayın</a>'; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include ("conn.php"); | |
$query = $db->query("SELECT * FROM dbtest", PDO::FETCH_ASSOC); | |
if ( $query->rowCount() ){ | |
foreach( $query as $row ){ | |
print "<div style='padding:5px; margin:5px; background-color:#fff;'>"."Kullanıcı adın : ".$row['dbname']."<br>"."Şifren : ".$row['dbpassword']."</div>"; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
yazdınızmı hocam?