I'm working on a project and I'm blocked by lack of knowledge. The code works but I don't know if the website 3 sees it as if it was clicked by a human.
Let me explain: I have 3 websites in total.
Website 1 redirect to Website 2 when clicking on a button.
Website 2 check if the referrer comes from Website 1 and automatically redirect to Website 3.
I need the redirect (Website 2 -> Website 3) to look as if the button was clicked by a human and not to show that I have redirected it automatically.
Code so far:
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();
}
I need the last part to make the redirect (website 2 -> website 3) as if it was clicked by a human.
In the code below I'm getting it but I don't know if it's the best way or if it's right:
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();
}
Website 3 checks referrer and all things to find that it's a human click
Theoretically you could issue the click event on the element that handles it, but that's probably as close as you can get without using any sort of external automated testing tool which would do the clicking. PHP is executed on the server side, while JavaScript is executed on the client's side, so it would actually seem like the client's browser did the trigger rather than the application doing it.
<script>
let elementYouWantToClick = document.getElementById('whatever-the-id-is');
elementYouWantToClick.click();
</script>