<?php
/*
Local:	C:\Dropbox\htdocs\RND\AnonymousChatApp\apiServer\Apiserver
Remote:	/var/www/mingle.eft.xyz/html
Local URL: https://mingle.eft.xyz/join.php?clickid=123&server_ref=ABC

https://mingle.eft.xyz/join.php?clickid={clickid}&publisherid={publisherid}

eg:- https://mingle.eft.xyz/join.php?clickid=123456&publisherid=10002


Redirect to -> https://play.google.com/store/apps/details?id=xyz.eft.mingle&clickid=123&server_ref=ABC
*/

require_once("includes/common-variables.php");
require_once("includes/common-functions.php");

$remote_ip_address = $_SERVER['REMOTE_ADDR'];

// 1. Capture the parameters from the URL
// We use filter_input or htmlspecialchars for basic security/sanitization
$clickid    = isset($_GET['clickid']) ? $_GET['clickid'] : '';
$server_ref = isset($_GET['publisherid']) ? $_GET['publisherid'] : '';

// 2. Construct the destination URL
$baseUrl = "https://play.google.com/store/apps/details?id=xyz.eft.mingle&referrer=";
//https://play.google.com/store/apps/details?id=xyz.eft.mingle&referrer=clickid%3D123%26server_ref%3DABC

// $redirectUrl = $baseUrl . "clickid=" . urlencode($clickid) . "&server_ref=" . urlencode($server_ref);

$baseUrl = "https://play.google.com/store/apps/details?id=xyz.eft.mingle&referrer=";

$referrer = http_build_query([
    'clickid'    => $clickid,
    'server_ref'=> $server_ref,
]);

$redirectUrl = $baseUrl . urlencode($referrer);

//https://play.google.com/store/apps/details?id=xyz.eft.mingle&referrer=clickid%3D123%26server_ref%3DABC

// echo $redirectUrl;
// exit;

writetolog("REDIRECT|" . $clickid .'|'. $server_ref ,$promologfile);

// 3. Perform the 302 (Temporary) Redirect
header("Location: " . $redirectUrl);

// 4. Ensure no further code is executed
exit;

?>