Last active
August 17, 2022 13:54
-
-
Save chenshaoju/7dc210bcaa6f532a9919b3254a13fc9c to your computer and use it in GitHub Desktop.
URL Jumping (PHP+MySQL)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Example: http://example.com/jump.php?go=0 | |
Alternative: | |
https://github.com/YOURLS/YOURLS | |
https://github.com/cydrobolt/polr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE IF NOT EXISTS `shortlinks` ( | |
`id` int(11) DEFAULT NULL, | |
`url` text DEFAULT NULL | |
) ENGINE=InnoDB DEFAULT CHARSET=latin1; | |
DELETE FROM `shortlinks`; | |
INSERT INTO `shortlinks` (`id`, `url`) VALUES | |
(0, 'https://www.google.com'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$id = $_GET['go']; | |
is_numeric($id) or die("PARAMETERS ARE NOT A NUMBER"); | |
$servername = "SERVER"; | |
$username = "USERNAME"; | |
$password = "PASSWORD"; | |
$dbname = "DBNAME"; | |
$conn = new mysqli($servername, $username, $password, $dbname); | |
if ($conn->connect_error) | |
{ | |
die("Connection failed: " . $conn->connect_error); | |
} | |
$sql = "SELECT url FROM shortlinks WHERE id={$id}"; | |
$result = $conn->query($sql); | |
if (mysqli_num_rows($result) > 0) | |
{ | |
while ($rowData = mysqli_fetch_array($result)) | |
{ | |
header("location: " . $rowData["url"]); | |
} | |
} | |
else | |
{ | |
echo "NO DATA"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment