git.php Şeklinde Yönlendirme Sayfası Yapımı

12 Mayıs 2017 - 124212 görüntüleme – 9 dakikada okunabilir.
Birçok sitede kullanılan git.php go.php redirect.php gibi yönlendirme sayfalarından yapımı.
Kullanımı
- config.php içerisinde websiteUrl kısmına git.php dosyasının bulunacağı adresi yazın. Örnek:
https://sitem.com/git.php - salt kısmına herhangi bir metin yazın. URL ve hashin doğru olup olmadığını kontrol etmekte gerekli.
- time kısmını yönlendirmeden önce kaç saniye bekletileceğini girin.
- config.php ve git.php dosyalarını sunucunuza yükledikten sonra link-olustur.php dosyasını kullanarak link oluşturabilirsiniz.
Kodları indirmek için tıklayın.
link-olustur.php için kodlar
<?php require_once __DIR__ . '/config.php'; ?> <!doctype html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/milligram/1.4.1/milligram.css"> <title>Link Oluştur</title> </head> <body> <div class="container"> <div class="row"> <div class="column" style="margin-top: 5rem;"> <h1>Link oluşturma</h1> <form action="" method="post"> <fieldset> <label for="url">Yönlendirmek istediğiniz URL</label> <input type="url" name="url" placeholder="URL (Zorunlu)" value="" required> <input type="hidden" name="salt" placeholder="Salt" value="<?php $config['time']; ?>"> <label for="utmSource">UTM Kampanya Kaynağı (siteadi, newsletter, google vb.)</label> <input type="text" name="utmSource" placeholder="UTM Campaign Source" value=""> <label for="utmMedium">UTM Campaign Medium (banner, email, footer vb.)</label> <input type="text" name="utmMedium" placeholder="UTM Campaign Medium" value=""> <label for="utmName">UTM Campaign Name (Ürün, promosyon kodu veya slogan. bahar_indirimi vb.)</label> <input type="text" name="utmName" placeholder="UTM Campaign Name" value=""> </fieldset> <button type="submit" class="button">Link Oluştur</button> </form> <?php if (isset($_POST['url']) != '') { $utmQuery = http_build_query(['utm_source' => $_POST['utmSource'], 'utm_medium' => $_POST['utmMedium'], 'utm_campaign' => $_POST['utmName']]); if ($utmQuery == 'utm_source=&utm_medium=&utm_campaign=') { $utmQuery = ''; } $parseUrl = parse_url($_POST['url']); if (!isset($parseUrl['query'])) { $parseUrl['query'] = $utmQuery; } else if (!empty($utmQuery)) { $parseUrl['query'] .= '&' . $utmQuery; } $newUrl = $parseUrl['scheme'] . '://' . $parseUrl['host'] . $parseUrl['path'] . '?' . $parseUrl['query']; $newUrl = $config['websiteUrl'] . '?' . http_build_query(['url' => $newUrl, 'hash' => sha1($newUrl . $config['salt'])]); printf('<a class="button button-outline" href="%s" target="_blank" style="word-break: break-all;white-space: normal;height: auto;">%s</a>', $newUrl, $newUrl); } ?> </div> </div> </div>
config.php için kodlar
<?php $config = [ 'websiteUrl' => 'http://localhost/one-file/redirector/git.php', 'salt' => 'SALT', 'time' => 10 ];
git.php için kodlar
<?php require_once __DIR__.'/config.php'; if (isset($_GET['url']) != '' && isset($_GET['hash']) != '') { $url = urldecode($_GET['url']); if (filter_var($url, FILTER_VALIDATE_URL)) { $hash = sha1($url . $config['salt']); if (hash_equals($hash, $_GET['hash'])) { $redirectUrl = $url; } else { http_response_code(403); } } else { http_response_code(404); } } else { http_response_code(404); } if (!isset($redirectUrl)) { die("Hatalı URL!"); } ?> <!doctype html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/milligram/1.4.1/milligram.css"> <title>Yönlendirme Sayfası</title> </head> <body> <div class="container"> <div class="row"> <div class="column" style="margin-top: 5rem;"> <h1>Lütfen bekleyin</h1> <p><span id="counter"><?php echo $config['time']; ?></span> saniye içerisinde otomatik yönlendirileceksiniz.</p> <a href="<?php echo $redirectUrl; ?>" class="button">Git</a> </div> </div> </div> <script type="text/javascript"> const url = "<?php echo $redirectUrl; ?>"; function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } var counter = <?php echo $config['time']; ?>; var inst = setInterval(change, 1000); function change() { document.getElementById("counter").innerHTML = counter; counter--; if (counter <= 0) { counter = 0; clearInterval(inst); } } async function redirect(url) { await sleep(<?php echo $config['time'] * 1000; ?>); window.location.href = url; } redirect(url); </script> </body> </html>