The following happens to me:
I call a function php
from the event onclick
, my problem is that the php function is executed whenever the page is loaded, that is, ignores the onclick
.
<a href="archivo.pdf" onclick="funcion()"/a>
- Probe by calling the function that is on a php page.
- Probe by calling the php page.
- Probe calling a javascript function and in this function is the called the php function.
In all cases the same thing happens to me, the php function is executed whenever the page is loaded ignores the onclick.
$visitas1 = array();
$visitas1 = contVisitas1();
function contVisitas1(){
$archivo = "contador1.txt";
$info = array();
if (file_exists($archivo)){
$fp = fopen($archivo,"r");
$contador = fgets($fp, 26);
$info = explode(" ",$contador);
fclose($fp);
$mes_actual = date("m");
$mes_ultimo = $info[0];
$visitas_mes = $info[1];
$visitas_totales = $info[2];
}else{
$mes_actual = date("m");
$mes_ultimo = "0";
$visitas_mes = 0;
$visitas_totales = 0;
}
if ($mes_actual==$mes_ultimo){
$visitas_mes++;
}else{
$visitas_mes=1;
}
$visitas_totales++;
$info[0] = $mes_actual;
$info[1] = $visitas_mes;
$info[2] = $visitas_totales;
$info_nueva = implode(" ",$info);
$fp = fopen($archivo,"w+");
fwrite($fp, $info_nueva, 26);
fclose($fp);
return $info;
}