-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredirect.php
More file actions
30 lines (24 loc) · 739 Bytes
/
Copy pathredirect.php
File metadata and controls
30 lines (24 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
// Connect to the database (change these settings)
$host = 'localhost';
$username = 'your_username';
$password = 'your_password';
$database = 'your_database';
$conn = new mysqli($host, $username, $password, $database);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Get the short code from the URL
$short_code = $_GET['code'];
// Retrieve the original URL from the database
$sql = "SELECT original_url FROM url_shortener WHERE id = '$short_code'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$original_url = $row['original_url'];
header("Location: $original_url");
} else {
echo "Short URL not found.";
}
$conn->close();
?>