When you want to share some data and it should be expired after the number of view then take a look at this work.
The below demo will generate a link which will be expired after single view.
This is fofG.php which generate links. DB schema at the bottom.
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
<?php $actionGen = isset($_POST["gen"]) ? 1 : 0; if ($actionGen) { $hofHash = md5(uniqid(rand(), true)); //insert and respond $con = mysqli_connect("localhost", "username", "password", "database"); $in1 = "INSERT INTO `fof`(`fofHash`, `isBurned`, `content`, `ip`) VALUES ('" . $hofHash . "',0,'<li class=\"w3-black\">Price list</li><li>iphone X 600USD</li> <li>One plus 6 500USD</li> <li>Samsung s10 1200 USD</li>','')"; mysqli_query($con, $in1); } ?> <!DOCTYPE html> <html> <title>Generate one time Link</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> <head> </head> <body> <div class="w3-container"> <p>One time Link Generator</p> <?php if (!$actionGen) { ?> <div class="w3-bar"> <form name="generateH" method="post"> <button class="w3-button w3-teal" name="gen">Generate Link</button> </form> </div> <?php } ?> <?php if ($actionGen) { ?> <div class="tooltip"> <p><?php echo $_SERVER['HTTP_HOST'] . "/fof/fofAuth.php?fofAuth=" . $hofHash; ?></p> </div> <a href="fofG.php" class="w3-button w3-teal">Back</a> <?php } ?> </div> </body> </html> |
This is fofAuth.php which will render the data you want to share and can be viewed only once.
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
<?php function getUserIP() { // Get real visitor IP behind CloudFlare network if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) { $_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"]; $_SERVER['HTTP_CLIENT_IP'] = $_SERVER["HTTP_CF_CONNECTING_IP"]; } $client = @$_SERVER['HTTP_CLIENT_IP']; $forward = @$_SERVER['HTTP_X_FORWARDED_FOR']; $remote = $_SERVER['REMOTE_ADDR']; if (filter_var($client, FILTER_VALIDATE_IP)) { $ip = $client; } elseif (filter_var($forward, FILTER_VALIDATE_IP)) { $ip = $forward; } else { $ip = $remote; } return $ip; } $user_ip = getUserIP(); $con = mysqli_connect("localhost", "username", "password", "database"); $fofId = mysqli_real_escape_string($con, htmlspecialchars($_REQUEST['fofAuth'])); $fofContent = "<p class='w3-center'>Not a valid hash or the one time link has expired. Contact skype: xyz OR Email:xyz@outlook.com :-)</p>"; $result = mysqli_query($con, "SELECT isBurned,content FROM fof WHERE fofHash= '" . $fofId . "' AND isBurned=false"); $match = mysqli_num_rows($result); if ($match > 0) { $row = mysqli_fetch_array($result); $fofContent = $row[1]; mysqli_query($con, "UPDATE fof SET isBurned = TRUE,ip = '" . $user_ip . "' WHERE fofHash= '" . $fofId . "'"); } ?> <!DOCTYPE html> <html> <title>HOF Price List</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> <body> <div class="w3-container"> <ul class="w3-ul w3-hoverable"> <?php echo $fofContent; ?> </ul> </div> <footer>Note: Try reopening the link</footer> </body> </html> |
schema name “fof”
1 2 3 4 5 6 7 |
CREATE TABLE fof ( fofHash varchar(1000) NOT NULL, isBurned tinyint(1) NOT NULL, content varchar(10000) NOT NULL, ip varchar(300) NOT NULL, UNIQUE KEY hofHash (fofHash) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; |
Demo – http://www.iseebug.com/fof/fofG.php Link Generator
Download- http://www.iseebug.com/loads/fof.rar