php - 使用 PHP 检测历史变化?

标签 php javascript

下面是我会用 JavaScript 做的事情。有没有办法在 php 中做到这一点? 我正在开发一个需要此功能但不能使用 JavaScript 的项目。

setInterval ( "checkHistory()", 1000 );

function checkHistory() {
   if (oldHistLength != history.length) {
      removegateway();
      oldHistLength = history.length;
   }
}

最佳答案

很抱歉,使用 PHP 无法做到这一点。您唯一的选择是在某处使用 JavaScript。

然而,您可以实现我认为您正在尝试使用另一种技术实现的目标 - PHP session 和请求 URI。

这涉及将用户访问的 URL 存储到一个变量(或者您可以使用 MySQL)中,该变量可以在当前 session 中在网站上的任何位置引用。

这是一个(未经测试的)示例:

<?php
session_start();

// Retrieve/create the current list
if( isset($_SESSION['history']) ) {
    $history = $_SESSION['history'];
} else {
    $history = new array();
}

// Add the current URL to the history array
array_push($history, $_SERVER['REQUEST_URI']);

// Do anything else you want to here

// Store the array again
$_SESSION['history'] = $history;
?>

关于php - 使用 PHP 检测历史变化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10417466/

相关文章:

javascript - 如何让 jQuery scrollTo 插件在 Facebook 中运行

php如何剪切数组并向其中添加另一个字符

php - 编写好的 PHP 文档的资源

javascript - 当我在 C++ 附加组件中创建 ArrayBuffer 时,node-webkit 崩溃

javascript - jQuery 自执行函数未触发

javascript - 将类方法绑定(bind)到类外绑定(bind)的事件处理程序中的 AJAX 成功回调

php - 调试时让 xdebug 跳过某些功能

php - 如何发出生成与 Firefox 相同的响应 header 的 cURL 请求

php - Paypal 捐赠 CodeIgniter

javascript - 函数的目的仅返回 bool 值