Jump to content
Sign in to follow this  
Elektron

Contador de visitas

Recommended Posts

Elektron

Estou a tentar fazer um contador de visitas em php.

<html>
<body>
<?php
$_d=fopen("data.txt","r+");
while ((flock ($_d,LOCK_EX))==TRUE)
{
}
$_var=TRUE;
flock($_d,LOCK_EX,$_var);
  $_s=fgets($_d); 
  $_i=(int)$_s;
  $_i=$_i+1;
  $_s=strval($_i);
  echo $_i;
  rewind($_d);
  fwrite($_d,$_s);
flock($_d,LOCK_UN); 
  fclose($_d);
?>
</body>
</html>

Tentei usar flock mas mesmo assim, quando abro duas abas do browser as duas retornam o mesmo valor.

Desde ja agradeço as respostas.


Making classic games.

Share this post


Link to post
Share on other sites
softklin

Porque escreves o $_s no ficheiro, quando deveria ser o $_i, não testei, mas pareceu-me ser disso.


Nick antigo: softclean | Tens um projeto? | Wiki P@P

Ajuda a comunidade! Se encontrares algo de errado, usa a opção "Denunciar" por baixo de cada post.

Share this post


Link to post
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
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.