pekmezcimuzo adlı üyeden alıntı: mesajı görüntüle
Lakin düzeltsenizde birşey olmayacaktır, o yüzden ben size tam kodu yazayım. Aşağıya yazacağım kod sorunsuz çalışmaktadır.


db.php
<?php $servername = "localhost"; $username = "root"; $password = ""; $dbname = "url_shortener"; $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) {    die("Connection failed: " . $conn->connect_error); } ?>
link_kisalt.php
<?php include 'db.php'; function generateShortUrl() {    return substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 6); } if ($_SERVER['REQUEST_METHOD'] == 'POST') {    $original_url = $_POST['original_url'];        //burada veritabanında daha önceden böyle bir kısaltma varmı diye kontrol ediyoruz hocam    $sql = "SELECT short_url FROM links WHERE original_url = ?";    $stmt = $conn->prepare($sql);    $stmt->bind_param("s", $original_url);    $stmt->execute();    $stmt->bind_result($short_url);    $stmt->fetch();    $stmt->close();        if ($short_url) {        echo "Short URL: " . $short_url;    } else {        $short_url = generateShortUrl();                $sql = "INSERT INTO links (original_url, short_url) VALUES (?, ?)";        $stmt = $conn->prepare($sql);        $stmt->bind_param("ss", $original_url, $short_url);                if ($stmt->execute()) {            echo "Short URL: " . $short_url;        } else {            echo "Error: " . $sql . "<br>" . $conn->error;        }                $stmt->close();    } } $conn->close(); ?>
db.php
<?php include 'db.php'; $short_url = $_GET['short']; $sql = "SELECT original_url FROM links WHERE short_url = ?"; $stmt = $conn->prepare($sql); $stmt->bind_param("s", $short_url); $stmt->execute(); $stmt->bind_result($original_url); $stmt->fetch(); if ($original_url) {    header("Location: " . $original_url);    exit(); } else {    echo "URL not found."; } $stmt->close(); $conn->close(); ?>
index.php
<!DOCTYPE html> <html> <head>    <title>URL Shortener</title> </head> <body>    <h1>URL Shortener</h1>    <form method="post" action="shorten.php">        <label for="original_url">Original URL:</label>        <input type="text" id="original_url" name="original_url" required>        <button type="submit">Shorten</button>    </form> </body> </html>
RewriteEngine On
RewriteRule ^([a-zA-Z0-9]{6})$ yonlendirme.php?short=$1 [L]
2 adet db.php