Last active
October 26, 2023 07:04
-
-
Save sonerufler/914407fbd7e1bd847565 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>"; | |
} | |
} | |
?> |
sarikayaemin
commented
Oct 26, 2023
via email
??
26 Eki 2023 Per, saat 01:30 tarihinde izzetuysal ***@***.***>
şunu yazdı:
… ***@***.**** commented on this gist.
------------------------------
$name =$_POST["name"];
PDO'da post yada get ile veri alırken strip_tags yada sayısal verileri
alırken intval falan kullanmak gerekiyor mu?
PHP dilinde buna gerek yoktur. Değişken tipi aldığı değere göre
nitelendirilir.
*örn:* $value = 3.14; // Ondalıklı sayı tipinde nitelendirilir.
strip_tags yada htmlspecialchars kesinlikle kullanmak zorundasın dostum,
aksi halde xss açığı bırakmış olursun, bütün veri tabanını çöp edebilirler
yada senin sitede istedikleri kodu ekleyebilirler.
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/sonerufler/914407fbd7e1bd847565#gistcomment-4738811>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJCQRTELYST5B5OF5TGKOUTYBGHHDBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVAZDAMBVHEZTGMNHORZGSZ3HMVZKMY3SMVQXIZI>
.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment