如何像人类一样模拟点击重定向



我正在做一个项目,但由于缺乏知识而受阻。代码有效,但我不知道网站3是否认为它是被人点击的。

让我解释一下:我总共有3个网站。

  • 点击按钮时,网站1重定向到网站2。

  • 网站2检查推荐人是否来自网站1,并自动重定向到网站3。

我需要重定向(网站2->网站3(,以使按钮看起来像是被人点击的,而不是显示我已自动重定向。

到目前为止的代码:

if (isset($_SERVER['HTTP_REFERER'])) {
$url_info = parse_url($_SERVER['HTTP_REFERER']);
$countCharacter = substr_count($url_info['host'], '.');
if($countCharacter == 2){
$eldominio = explode(".", $url_info['host']);
$elhost = $eldominio[1];
}else if($countCharacter == 1){
$eldominio = explode(".", $url_info['host']);
$elhost = $eldominio[0];
}
//if referrer contain $elhost
if($elhost == 'website1' || $elhost == 'website2'){
$tieneHostaff = "yes";
}else{//no host}
} else {  // referrer does not exist 
session_start();
if($tieneHostaff=="yes" && isset($_GET['q']) && !empty($_GET['q'])){
//Create sessions and delete actual referrer
$_SESSION['nombre'] = "y";
$_SESSION['producto'] = $_GET['q'];
echo "<script>window.location.reload(true);</script>";
exit();
}
if($_SESSION['nombre'] == "y"){
// Destroy session and redirect to website 3
session_unset();
echo "<script>window.location.href = 'https://website3.com/".$_SESSION['producto']."'</script>";
exit();
}

我需要最后一部分来重定向(网站2->网站3(,就好像它被人点击了一样。

在下面的代码中,我得到了它,但我不知道这是最好的方式还是正确的:

if($_SESSION['nombre'] == "y"){
// Destroy session and redirect to website 3
session_unset();
echo "<script>window.location.href = 'https://website3.com/".$_SESSION['producto']."'</script>";
exit();
}

网站3检查推荐人和所有的东西,发现这是一个人点击

理论上,您可以在处理它的元素上发出点击事件,但这可能是在不使用任何类型的外部自动测试工具来进行点击的情况下所能达到的。PHP是在服务器端执行的,而JavaScript是在客户端执行的,所以看起来实际上是客户端的浏览器触发的,而不是应用程序触发的

<script>
let elementYouWantToClick = document.getElementById('whatever-the-id-is');
elementYouWantToClick.click();
</script>

最新更新