Make button to change href="" every new access on a certain page

5

I have a small question in a project I'm developing.

The following happens, I have 2 buttons on the page, like these ( identical in different positions ):

Top of the page:

<a target="_blank" class="btn-primary" href="http://localhost/exemplo/"> Clique Aqui </a>

To end the page:

<a target="_blank" class="btn-primary" href="http://localhost/exemplo/"> Clique Aqui </a>

I need to make every time the page containing these buttons is accessed, increase the number in the folder. Example:

One person has accessed this page the first time: (Note that the link contains / 01 / )

http://localhost/exemplo/01/

When a other person accesses the second time: (Note that the link contains / 02 / )

http://localhost/exemplo/02/

And so on: / 03 / , / 04 / , / 05 / , / 06 / , etc ...)

Each new access increases the value on the link incrementally.

Furthermore, is it possible to implement something that can tell me what number it is at the moment? I have no idea, maybe something like a file that is updated (txt maybe) , informing me on which number it stopped.

    
asked by anonymous 11.10.2016 / 05:20

1 answer

3

You can simply use .htaccess so that whenever the link is clicked, the page passes the value to PHP:

RewriteRule ^exemplo/([0-9]*)/$ index.php?contador=$1 [QSA,L]

Then in% w / o% just increase this counter by 1 and print the link:

$contador = $_GET['contador'] + 1;
echo "<a target='_blank' class='btn-primary' href='http://localhost/exemplo/".$contador."/'> Clique Aqui </a>";

Or you can use the file read if you are loading the page:

$file = 'exemplo.txt'; 

$atual = file_get_contents($file); 

$contador = $atual + 1 ;

echo "<a target='_blank' class='btn-primary' href='http://localhost/exemplo/".$contador."/'> Clique Aqui </a>";

Finally, to write to a file you can use the index.php function, for example:

$file     = 'exemplo.txt'; 
file_put_contents($file, $contador);

Note: Keep in mind what you are going to use this for, you may be misusing it.

    
11.10.2016 / 18:00