1
I have a little doubt in a project that 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>
End of page:
<a target="_blank" class="btn-primary" href="http://localhost/exemplo/"> Clique Aqui </a>
I need to make sure that each time the page containing these buttons is accessed by a new visitor, increase the number in the folder. Example:
If a person visited this page the first time: ( Note that the link contains /01/ )
http://localhost/exemplo/01/
When a another person accesses for the second time: ( Note that the link contains /02/ )
http://localhost/exemplo/02/
And so consecutively: (/03/, /04/, /05/, /06/, etc....)
To each new visitor on this page, that is, (with each new IP) increase the link value, increasing.
related http://answall.com/q/157907/4793
– Daniel Omine
I’m gonna go check on Dani :)
– Alexandre Lopes
Daniel, yes, that’s another example (adds +1 to each "F5" reload), in this example, I want you to add just to each new visitor "IP".
– Alexandre Lopes
You already have the logic that solved the old question. Use that same logic and adapt it to this new business rule (the schema with IP).
– Daniel Omine
What exactly do you need different Ips for? Another method to detect if that user has already been to the site is not enough?
– Ricardo Moraleida
I agree with @Danielomine the question is practically identical, just adapt the logic checking only the IP, IE can change the
$file = 'exemplo.txt';
for$file = $_SERVER['REMOTE_ADDR'].'.txt';
– Guilherme Nascimento
@Guilhermenascimento is clearly duplicate. But since this is someone else’s, you can’t use the comments to detail the service.
– Bacco
@Guilhermenascimento But if you make this change, it will not work, as +1 will be added to each reload in the file, causing all visitors to start with "http://localhost/example/01/" and if they update, they will add +1, and the question is just add +1 for each visitor, if it is not a new visitor, the number that is written in this TXT file remains the same.
– Alexandre Lopes
The
$_SERVER['REMOTE_ADDR']
that @Guilhermenascimento said is precisely to resolve what you just said. It separates by IP if use as in the given example.– Bacco
Yes @Bacco it writes a file. TXT renamed with the visitor’s IP, but what happens... As I said before, in case I access the first time, it will be "1", if I access the second "2", and so consecutively for all, IE, all will start with "1", and the right is to start from where you left off. The right would be to check if there is a file . TXT created with the IP number, if not, it will add +1 in another file . TXT, in this case this
$file = 'exemplo.txt';
.– Alexandre Lopes
That I don’t know how to do :(
– Alexandre Lopes
is the meso example of the @Jorgeb answer. there in the other question http://answall.com/a/158024/3635 just change the
$file = 'exemplo.txt';
by the visitor’s IP, and will continue where it left off, this in both file_get_contents and file_put_contents– Guilherme Nascimento
I did what you said, it turns out that it creates a new file with the IP number, only that this file ex: (123.432.445.43.txt) always starts with "1". I mean, any visitor will start with
http://localhost/exemplo/01/
, and if reloading will increase the number, and what I want is precisely to prevent it to be increased without need, just start from where you left, and if there is no file . txt with the display IP, if +1 is added to another fileexemplo.txt
.– Alexandre Lopes
I guess I’ll have to ask a question about that.
– Alexandre Lopes
According to this reply you just use the
.htaccess
, to pass the link.– Mineiro
@Alexandrelopes you have already solved the matter?
– Jorge B.
Yes @Jorgeb. :D Here.
– Alexandre Lopes
It seems that it was solved in the duplicate question: http://answall.com/questions/167993/php-cria-arquivo-txt-com-log-de-ips-dos-visitors
– Daniel Omine