Javascript 如何在php中通过基于按钮操作的点击数计数
我们正在开发网络坐姿。我们有按钮。在按钮操作中,我们放置了PDF文件下载。工作正常。但我们需要如何计算从我的网站下载我的PDF文件 我们这样试过,但没有成功Javascript 如何在php中通过基于按钮操作的点击数计数,javascript,php,onclick,file-get-contents,file-put-contents,Javascript,Php,Onclick,File Get Contents,File Put Contents,我们正在开发网络坐姿。我们有按钮。在按钮操作中,我们放置了PDF文件下载。工作正常。但我们需要如何计算从我的网站下载我的PDF文件 我们这样试过,但没有成功 <?php //$Down=$_GET['Down']; $a="hello"; $i=0; ?> <script type="text/javascript"> var i=0; function submitForm() { <?php $i = @f
<?php
//$Down=$_GET['Down'];
$a="hello";
$i=0;
?>
<script type="text/javascript">
var i=0;
function submitForm()
{
<?php
$i = @file_get_contents('count.txt'); // read the hit count from file
echo $i; // display the hit count
$i++; // increment the hit count by 1
@file_put_contents('count.txt', $i); // store the new hit count
?>
}
</script>
<html>
<head>
</head>
<body>
<input type="button" onclick="submitForm()" value="submit 1" />
</body>
</html>
var i=0;
函数submitForm()
{
}
我们什么都没有。我们是新来的
PHP
请指导我们。你把PHP和Javascript混合在一起,这根本不起作用。最好的解决方案是创建一个PHP脚本,按照上面所示进行计数,然后将PDF作为附件发送
一些例子:
您将PHP与Javascript混用,这根本行不通。最好的解决方案是创建一个PHP脚本,按照上面所示进行计数,然后将PDF作为附件发送 一些例子:
好的,您可以下载PDF并在表单提交时计数:
<?php
$i=0;
$i = (int) @file_get_contents('count.txt'); // read the hit count from file
if(!empty($_POST)) {
$i++; // increment the hit count by 1
@file_put_contents('count.txt', $i); // store the new hit count
// Download
$file = 'filename.pdf';
header('Content-Description: File Transfer');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
}
好的,您可以下载您的PDF并在表单提交时计数:
<?php
$i=0;
$i = (int) @file_get_contents('count.txt'); // read the hit count from file
if(!empty($_POST)) {
$i++; // increment the hit count by 1
@file_put_contents('count.txt', $i); // store the new hit count
// Download
$file = 'filename.pdf';
header('Content-Description: File Transfer');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
}
如何下载PDF?@SpartakusMd很可能是表单目标,但不确定。使用$\u会话保存$i变量;执行类似$_SESSION['count']=$i;别忘了启用“session_start()”()@SpartakusMd下载的会话,如“download onclick=“redirect()”;“>为此或Ajax使用数据库。您如何下载PDF?@SpartakusMd很可能是表单目标,但不确定。使用$\u SESSION保存$i变量;执行类似$\u SESSION['count']=$i的操作;不要忘了使用“SESSION\u start()”()@SpartakusMd下载类似于“download onclick=”redirect();”>为此或Ajax使用数据库。
$file='filename.pdf'
@SpartakusMd非常感谢,我们需要精确的数据,但需要显示计数。我们尝试使用此echo$i,但没有displayed@SpartakusMd感谢更新,我们尝试过这样做,但它不是更新按钮。单击“请向我们提供指南”。我们对此$file='filename.pdf'
@SpartakusMd非常感谢我们需要精确的显示计数,但我们需要像echo$i这样尝试,但它不是displayed@SpartakusMd感谢更新,我们尝试过这样做,但它不是更新按钮点击请指导我们。我们是新的这一点