Severity: 8192
Message: Return type of CI_Session_files_driver::open($save_path, $name) should either be compatible with SessionHandlerInterface::open(string $path, string $name): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Filename: drivers/Session_files_driver.php
Line Number: 113
Severity: 8192
Message: Return type of CI_Session_files_driver::close() should either be compatible with SessionHandlerInterface::close(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Filename: drivers/Session_files_driver.php
Line Number: 280
Severity: 8192
Message: Return type of CI_Session_files_driver::read($session_id) should either be compatible with SessionHandlerInterface::read(string $id): string|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Filename: drivers/Session_files_driver.php
Line Number: 145
Severity: 8192
Message: Return type of CI_Session_files_driver::write($session_id, $session_data) should either be compatible with SessionHandlerInterface::write(string $id, string $data): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Filename: drivers/Session_files_driver.php
Line Number: 223
Severity: 8192
Message: Return type of CI_Session_files_driver::destroy($session_id) should either be compatible with SessionHandlerInterface::destroy(string $id): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Filename: drivers/Session_files_driver.php
Line Number: 303
Severity: 8192
Message: Return type of CI_Session_files_driver::gc($maxlifetime) should either be compatible with SessionHandlerInterface::gc(int $max_lifetime): int|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Filename: drivers/Session_files_driver.php
Line Number: 344
Severity: 8192
Message: setcookie(): Passing null to parameter #7 ($httponly) of type bool is deprecated
Filename: core/Input.php
Line Number: 410
Bu yazıda PHP ile toplama işlemi yaparak güvenlik kodu oluşturacağız. Nasıl bir uygulama olacağını bu yazının yorum yap kısmında görebilirsiniz. Birkaç input ile form oluşturup toplama işlemiyle güvenlik kodunu ekleyeceğiz. Toplama işleminin sonucu session (oturum) ile kontrol edeceğiz. Eğer işlem doğruysa doğru olduğuna dair bilgi mesajı, yanlışsa da hata mesajı verecek.
Oluşturulan Form Görüntüsü
Toplam 2 tane php dosyası oluşturacağız. İlkinin ismi "toplama.php", ikincisinin ismi "sonuc.php" olacak.
toplama.php içerisinde resimdeki basit tasarımı oluşturmak için HTML ve CSS kodları, sayıları oluşturmak için de PHP kodları olacak. mt_rand() fonksiyonu ile sayıları oluşturacağız. Oluşturduğumuz sayıları topladıktan sonra session oluşturup toplamı session'a atayacağız. Daha sonra sayıları inputlarda göstereceğiz. Ben burada sayılar değiştirilmesin diye placeholder kullandım, aynı şekilde readonly kullanmak da mümkün. Son olarak "Gönder" butonuna basıp post metoduyla formu sonuc.php sayfasına gönderiyoruz, eğer toplama işlemini doğru yaptıysak işlemin doğru olduğuna dair bilgi mesajı, yanlış yaptıysak hata mesajı verecek.
sonuc.php içerisinde toplama.php'den alınan toplama sonucuyla (bizim girdiğimiz) ve session'da kayıtlı duran toplama sonucunu (gerçek sonuç) karşılaştıracağız. Dönen değere göre bilgi veya hata mesajı toplama.php içerisinde yazılacak.
Kodların bir kısmını örnek olması için paylaşıyorum, uygulamayı denemek için önizlemeyi, bütün kodları indirmek için indir butonuna tıklayabilirsiniz.
toplama.php => Sayı Oluşturma Kodları
<?php
$toplam1 = mt_rand(1,9);
$toplam2 = mt_rand(1,9);
session_start();
$toplam_sayi = $toplam1+$toplam2;
$_SESSION['toplama'] = $toplam_sayi;
?>
sonuc.php => Güvenlik Sorusunu Kontrol Kodları
<?php
$girilen_sonuc = $_POST['sonuc'];
session_start();
if($_SESSION['toplama'] != $girilen_sonuc)
$_SESSION['bilgi'] = "Hata";
else
$_SESSION['bilgi'] = "Doğru";
header("Location: toplama.php");
exit;
?>