Dün @KeyCodE; hocamın buradaki konumda isteği üzerine sabahtan birşeyler yapmaya çalıştım. Kod geliştirmeye fazlasıyla açık. Sadece temel olarak işlemi gerçekleştiriyor. güvenlik önlemi, kısaltılmış linkin asıl linke gitmesini sağlayan sayfaları kullanmak isteyen arkadaşlar ekleyebilir.

Paylaştığım Diğer Hazır Kodlar;
Süper Lig Puan Durumu (PHP)
Son Deprem Verileri (PHP)
Javascript ile Klavye Hız Testi
Javascript ile Vücut Kitle İndeksi Hesaplama
Javascript ile Kredi Hesaplama






<!DOCTYPE html>
<html>
<head>
    <title>URL Kısaltma Servisi</title>
    <style>
        body {font-family: Arial, sans-serif;background-color: #f7f7f7;margin: 0;padding: 0;}
        header {background-color: #333;color: #fff;text-align: center;padding: 10px;}
        .container {max-width: 600px;margin: 0 auto;padding: 20px;background-color: #fff;box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);border-radius: 4px;margin-top: 50px;}
        label {font-weight: bold;display: block;margin-bottom: 5px;}
        input[type="text"] {width: 96%;padding: 10px;border: 1px solid #ccc;border-radius: 4px;}
        button {background-color: #007bff;color: #fff;border: none;padding: 10px 20px;border-radius: 4px;cursor: pointer;width: 100%;margin-top:10px;}
        button:hover {background-color: #0056b3;}
        .result {margin-top: 20px;border: 1px solid #ccc;padding: 10px;border-radius: 4px;background-color: #f7f7f7;}
    </style>
</head>
<body>
    <header>
        <h1>URL Kısaltma Servisi</h1>
    </header>
    <div class="container">
    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
        <input type="text" name="original_url" placeholder="Kısaltılacak Linki Buraya Yazın." required>
        <button type="submit">Kısalt</button>
    </form>
    <?php
$servername = "localhost";
$username = "linkkisalt";
$password = "linkkisalt";
$dbname = "linkkisalt";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Veritabanı bağlantısında hata oluştu: " . $conn->connect_error);
}
function generateRandomString($length = 10) {
    $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, strlen($characters) - 1)];
    }
    return $randomString;
}
function isRandomStringExists($randomString, $conn) {
    $sql = "SELECT COUNT(*) as count FROM linkler WHERE short_url = '$randomString'";
    $result = $conn->query($sql);
    
    if ($result && $result->num_rows > 0) {
        $row = $result->fetch_assoc();
        return $row["count"] > 0;
    }
    return false;
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $original_url = $_POST["original_url"];
    do {
        $short_url = generateRandomString();
    } while (isRandomStringExists($short_url, $conn));
    
    $sql = "INSERT INTO linkler (original_url, short_url) VALUES ('$original_url', '$short_url')";
    echo "<div class='result'>";
    if ($conn->query($sql) === TRUE) {
        echo "<b>URL kısaltma başarılı!</b><br><br>";
        echo "Orijinal URL: $original_url<br>";
        echo "Kısaltılmış URL: <a target='_blank' href='https://site.com/$short_url'>https://site.com/$short_url</a>";
    } else {
        echo "Hata oluştu: " . $sql . "<br>" . $conn->error;
    }
    echo "</div>";
}
$conn->close();
?>
</body>
</html>