PHP Dersleri
PHP Güvenlik Kodu (Captcha) Uygulaması Yapımı
Bu rehberde, PHP kullanarak güvenlik kodu (captcha) uygulaması yaptık. uygulamayı yapmadan önce PHP ile captcha çalışabilmesi için GD kütüphanesinin aktif olması gerekmektedir.
GD kütüphanesini Kontrolü:
<?php
if (extension_loaded("gd")) {
echo "GD kütüphanesinin aktif";
} else {
echo "GD kütüphanesinin aktif değil.";
}
?>
Captcha Kodu:
<?php
session_start();
$image = @imagecreatetruecolor(120, 28) or die("hata oluştu");
$background = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
imagefill($image, 0, 0, $background);
$line_color = imagecolorallocate($image, 0xCC, 0xCC, 0xCC);
$text_color = imagecolorallocate($image, 0x33, 0x33, 0x33);
// rast gele çizgiler oluşturuyoruz
for ($i = 0; $i < 8; $i++) {
imagesetthickness($image, rand(1, 3));
imageline($image, 0, rand(0, 30), 120, rand(0, 30), $line_color);
}
$sayilar = '';
for ($x = 15; $x <= 95; $x += 20) {
$sayilar .= ($sayi = rand(0, 9));
imagechar($image, rand(3, 5), $x, rand(2, 14), $sayi, $text_color);
}
$_SESSION["captcha"] = $sayilar;
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>
PHP Dersleri
PHP Dinamik Sitemap.xml Oluşturma
Bu rehberimizde, Dinamik bir şekilde sitemap.xml oluşturacağız. Arama motoru optimizasyonu açısından önemi yüksektir. Çünkü web sitemizi indeksleyen robotlar, ön bilgileri bu sayfalardan alırlar.
database.php
<?php
$db_config = array(
'host' => "localhost",
'database' => "msyt", // veritabanı adı
'username' => "root", // veritabanı kullanıcıadı
'password' => "" // veritabanı kullanıcıadı şifresi
);
try{
$db = new PDO("mysql: host={$db_config['host']}; dbname={$db_config['database']}", $db_config['username'], $db_config['password']);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}catch(PDOException $e){
echo 'Bağlantı hatası: ' . $e->getMessage();
}
?>
sitemap.php
<?php header('Content-type: Application/xml; chatset="utf-8"', true); ?>
<?php echo '<?xml version="1.0" encoding="UTF-8" ?>'; ?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">
<?php
require_once('database.php');
$query = $db->prepare("SELECT * FROM pages");
$query->execute();
$data = $query->fetchAll(PDO::FETCH_ASSOC);
foreach($data as $dt){
echo '<url>';
echo '<loc>https://'.$_SERVER['SERVER_NAME'].'/'.$dt['page_sef'].'</loc>';
echo '<lastmod>'.date('Y').'-'.date('m').'-'.date('d').'T'.date('H:I:S').'00:00</lastmod>';
echo '<changefreq>weekly</changefreq>';
echo '</url>';
}
?>
</urlset>
.htaccess
RewriteEngine On
RewriteRule ^sitemap.xml$ sitemap.php [NC,L]
- PHP Dersleri2 hafta Önce
PHP Dinamik Sitemap.xml Oluşturma
- python3 ay Önce
Python Dijital Saat Yapımı
- PHP Dersleri4 ay Önce
PHP İle Web Sitelerde Çoklu Dil Yapısı
- JavaScript4 ay Önce
JavaScript Rastgele Background Rengi Değiştirme
- JavaScript6 ay Önce
JavaScript Vücut Kitle İndeksi Hesaplayıcı
- linux6 ay Önce
Kali Linux Kişiye Özel Wordlist Oluşturma
- python7 ay Önce
Python Mail Adresini Kontrol Etme
- JavaScript7 ay Önce
JavaScript İle Kalan Karakter Sayısını Bulma