Cesar, there are differences there.
You have created a function in PHP and are calling it via javascript. This will not work. Ideally you would work with ajax for this. So you get the javascript function to access the page with php done.
PHP does not know Javascript
PHP cannot directly call a Javascript function because PHP is interpreted on the server side.
PHP does not see a code there, it simply copies the text character by character and sends it to the user’s browser.
The browser knows Javascript
When the browser reads the received data already in HTML, it starts to interpret this HTML and assemble the elements on the screen.
When finding a tag the nevegador stops what it is doing and executes what it has in this script.
Note that at this point, the browser is running the script on the user’s computer, while PHP (which has possibly finished running) was running on the server.
Well, I’ll help you with ajax.
1) php page: call it log.php
<?php
echo date('H:i:s');
$fp = fopen('meus_links.txt', 'a');
fwrite($fp, date('H:i:s-'));
fclose($fp);
?>
2) In your index copy this code:
<form id="simples-formulario-ajax" method="post">
<button type="submit" name="enviar" value="enviar" id="enviar">
Clique aqui para criar um log :)
</button>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$('#simples-formulario-ajax').submit(function(e){
e.preventDefault();
if($('#enviar').val() == 'Enviando...'){
return(false);
}
$.ajax({
url: 'log.php',
type: 'post',
dataType: 'html',
data: {
'acao': 'log'
}
}).done(function(data){
alert("Log criado com sucesso");
});
});
</script>
All right, working like a beauty :)