php带refre获取网页内容,PHP:检测页面刷新

I have a page action.php on which I run an SQL query through the code, so that whenever the page is viewed the query runs like its like counting page views

mysqli_query("UPDATE ****");

?>

The problem is when the page is refreshed, the query is run & PAGE REFRESH is counted as a PAGE VIEW which I want to avoid.

Question: How to avoid it ?

What I am looking for is a simple solution so that I can check

if( page was refresh ) //some condition

{

do

}

解决方案

i have solved the problem ... HURRAHHH with no session & no cookies

the solution is a combination of PHP : AJAX : JavaScript

the query that you want to run on Page Load & not on page Refresh run it as via AJAX call lets say my function for doing that is

function runQUERY()

{

xmlhttp=new XMLHttpRequest();

xmlhttp.open("POST","doIT.php",false);

xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");

xmlhttp.send();

}

and i can simply check with Javascript that the page is a fresh load or its a refresh by doing the following

function checkRefresh()

{

if( document.refreshForm.visited.value == "" )

{

// This is a fresh page load

alert ( 'Fresh Load' );

document.refreshForm.visited.value = "1";

..call you AJAX function here

}

else

{

// This is a page refresh

alert ( 'Page has been Refreshed, The AJAX call was not made');

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值