Skip to content

Instantly share code, notes, and snippets.

@chenshaoju
Last active August 17, 2022 13:54
Show Gist options
  • Save chenshaoju/7dc210bcaa6f532a9919b3254a13fc9c to your computer and use it in GitHub Desktop.
Save chenshaoju/7dc210bcaa6f532a9919b3254a13fc9c to your computer and use it in GitHub Desktop.
URL Jumping (PHP+MySQL)
Example: http://example.com/jump.php?go=0
Alternative:
https://github.com/YOURLS/YOURLS
https://github.com/cydrobolt/polr
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');
<?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