wepay.php // Return from gateway -> wepay/callback.php (callback is inside /wepay) date_default_timezone_set('Asia/Kolkata'); // ---- Paths (relative to web root) ---- $PAYMENT_PATH = 'wepay.php'; // payment page in root $CALLBACK_PATH = 'wepay/callback.php'; // callback INSIDE /wepay folder function redirect_path(string $path, bool $keep_query = false) { $basePath = rtrim(dirname($_SERVER['PHP_SELF'] ?? '/'), '/\\'); $qs = $_SERVER['QUERY_STRING'] ?? ''; $url = ($basePath ? $basePath.'/' : '/') . ltrim($path, '/'); if ($keep_query && $qs) $url .= (strpos($url, '?') === false ? '?' : '&') . $qs; header('Location: ' . $url, true, 302); exit; } // Detect browser return from gateway $qs = $_SERVER['QUERY_STRING'] ?? ''; $looksLikeReturn = isset($_GET['cb']) || isset($_GET['status']) || isset($_GET['order_sn']) || isset($_GET['paymentId']) || isset($_GET['txnId']) || isset($_GET['signature']); // If return, forward to callback INSIDE /wepay with same query if ($looksLikeReturn) { redirect_path($CALLBACK_PATH, true); } // Otherwise go to payment page redirect_path($PAYMENT_PATH); ?>