KonataTheOtaku Posted December 10, 2014 Share Posted December 10, 2014 How would you go about making a hyperlink that can only be visited once before changing to another one? (Like tracking the amount of times the link was visited, and when it reaches a certain number it switches.) Link to comment Share on other sites More sharing options...
Ingolme Posted December 10, 2014 Share Posted December 10, 2014 Does it matter who has clicked on the link? That means: if person A clicks on the link, does person B from halfway across the world see the counter increase? Does this reset after each browsing session or is the change registered forever? Link to comment Share on other sites More sharing options...
KonataTheOtaku Posted December 11, 2014 Author Share Posted December 11, 2014 (edited) It wouldnt and you mean the link will change forever / after each browsing session, right? I was thinking as if one person who visits the link first gets to see one thing, and then everyone else who follows the link will be redirected somewhere else. (kind of like those things where it's only one per person.) Edited December 11, 2014 by KonataTheOtaku Link to comment Share on other sites More sharing options...
Ingolme Posted December 11, 2014 Share Posted December 11, 2014 You'll need to store some data on the server. I'd just make a file for it. The link will target a page, which I'll call "target.php". Inside target.php: <?php// Get the number from the file if the file existsif(file_exists('counter.txt')) { // Cast the contents of the file to an integer $counter = (int) file_get_contents('counter.txt');} else { // If the file does not exist, the counter is zero $counter = 0;}// If the page hasn't been visited yet the counter will be zero (and just in case we'll also include negative numbers)if($counter <= 0) {?><h1>Page content for first viewer</h1><?php} else {?><h1>Page content for all other viewers</h1><?php}// Increase the counter and save it to the file$counter++;file_put_contents('counter.txt', $counter);?> This is going to expire really quickly if it takes just a single visitor to make the first content unavailable forever. Link to comment Share on other sites More sharing options...
KonataTheOtaku Posted December 12, 2014 Author Share Posted December 12, 2014 Thank you~! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now