PHP 是否可以知道用户从哪个页面进入特定页面?
例如,第一页是 index.php
,第二页是 index2.php
。
现在,用户使用 index2.php
上的超链接从 index2.php
转到 index.php
。
现在我想将链接存储在数据库中,用于用户访问 index.php
的页面,在本例中为 index2.php
。
最佳答案
如果它在您自己的网站上,您不妨使用 session ,HTTP_REFERER
容易产生垃圾邮件,或者很可能根本没有设置,您不能信任它。
也许可以做这样的事情:
<?php
session_start();
if (!isset($_SESSION['last_page'])) {
// first visit (landing)
} else {
// not first page
}
// insert into db
// set tracking for next page
$_SESSION['last_page'] = [
'page' => $_SERVER['REQUEST_URI'],
'time' => time() // know how long user was on the last page
];
将其放置在每个页面上 HitTest 门的位置。
关于javascript - 我们能知道用户从哪个页面访问了php中的这个页面吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51807878/