Login bypass engellemek için filtreleme yardım
Admin panelime giriş kısmında OR"' gibi değişik kodlar ile bypass ediliyordu bende biraz araştırdım ve veriyi filtrelemek gerekli olduğunu duydum.
Ancak php bilgim çok çok yeni ve bir türlü yapamadım. Elimde bu kodlara nasıl bir kod eklersek filtreleme yapabilirim? Yarımcı olursanız çok teşekkür ederim.
<?php
error_reporting(0);
session_start();
include "baglan.php";
if ($connect->connect_error) {
die ("Bağlantı Hatası Oluştu");
}
if($_POST) {
$name = $_POST["kullaniciadi"];
$pass = $_POST["pass"];
$giris = "select * from admin where name='$name'and password='$pass'";
$getir = $connect->query($giris);
if ($getir->num_rows>0) {
while ($row = $getir->fetch_assoc()) {
$_SESSION["ID"] = $row["id"];
header("location:yonetim.php");
}
}
}
?>
- mysqli değil pdo kullan
- değişkenleri direk sorgu içinde kullanma
en basiti htmlentities kullanmak
AYRICA ÜYELERE sql de yetki ataması yap misal 0 olan üye 1 olan yönetici olsun
ve sorguda bunu kontol et
<?php
error_reporting(0);
session_start();
include "baglan.php";
if ($connect->connect_error) {
die ("Bağlantı Hatası Oluştu");
}
if($_POST) {
$name = htmlentities($_POST["kullaniciadi"]);
$pass = htmlentities($_POST["pass"]);
$giris = "select * from admin where name='$name'and password='$pass'";
$getir = $connect->query($giris);
if ($getir->num_rows>0) {
while ($row = $getir->fetch_assoc()) {
$_SESSION["ID"] = $row["id"];
header("location:yonetim.php");
}
}
}
?>
buda PDO hali
<?php
error_reporting(0);
session_start();
include "baglan.php";
if ($connect->connect_error) {
die ("Bağlantı Hatası Oluştu");
}
if($_POST) {
$name = htmlentities($_POST["kullaniciadi"]);
$pass = htmlentities($_POST["pass"]);
$giris =$connect->("select * from admin where name=? and password=? AND yetki=1");
$getir->execute([$name,$pass])
$say=$getir->rowCount();
if ($say==1) {
$_SESSION["ID"] = $row["id"];
header("location:yonetim.php");
}
}
?>