<\?php
define("SITEDIRECTORY","./"); //selon votre serveur php et site
/*on peut recopier le dossier /mesfilestxt/ par ftp sur un autre
serveur2 et rediriger anonymement dans redirect.php
https://serveur2/redirect.php?id=???? ce qui cachera IP source
du script ...
*/
define("SOMEFILESDIR","./mesfilestxt/");
function createLink($url){
// create_link.php
$real_url = $url; // The URL you want to shorten
$timestamp = time(); // Unique ID based on current timestamp (e.g., 1743641234)
file_put_contents(SOMEFILESDIR.$timestamp.'.txt', $real_url); // Save the URL in a file named with the timestamp
//echo "Your short link: redirect.php?id=$timestamp";
return $timestamp;
}
if(isset($_POST['sbtbtn'],$_POST['urlsite']) && $_SERVER['REQUEST_METHOD'] === 'POST' ){
$url=$_POST['urlsite'];
$newlink=createLink($url);
sleep(2);
echo ''.SITEDIRECTORY.'redirect.php?id='.$newlink.'';
/*<\iframe src="./redirect.php?id=1743585628">*/
/*<\img src="./redirect.php?id=1743585628"> ...*/
}
?>
<\?php
define("SOMEFILESDIR","./mesfilestxt/");
// redirect.php
if (isset($_GET['id'])) {
$id = $_GET['id'];
// Ensure ID is numeric (prevents directory traversal or invalid filenames)
if (!is_numeric($id) || $id < 0){
http_response_code(400); // Bad request
echo "Invalid ID!";
exit;
}
if(isset($id)){
$filename = "$id.txt";
// Check if file exists and is readable
if (file_exists(SOMEFILESDIR.$filename) && is_readable(SOMEFILESDIR.$filename)) {
$link = trim(file_get_contents(SOMEFILESDIR.$filename)); // Remove any whitespace from the URL
// Basic URL validation (optional, but good for production)
if (filter_var($link, FILTER_VALIDATE_URL)) {
header("Location: $link");
exit;
} else {
http_response_code(500); // Server error
echo "Invalid URL stored!";
exit;
}
} else {
http_response_code(404); // Not found
echo "Link not found!";
exit;
}
} else {
http_response_code(400); // Bad request
echo "No ID provided!";
exit;
}
}
?>
Aucun commentaire:
Enregistrer un commentaire