Jump to content

Redirecting links via click.


KonataTheOtaku

Recommended Posts

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

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 by KonataTheOtaku
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...