Guest User

Untitled

a guest
Jan 23rd, 2026
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.50 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. PHP Landing Manager
  5. (c) 2026 Alex Constantin aka LondoN eXtream
  6. Creator contact: https://steamcommunity.com/id/london_extreamcs
  7. */
  8.  
  9. function SafeJSONDecode ( string $json_payload ): array
  10. {
  11. try
  12. {
  13. $json_data = json_decode ( $json_payload, true, 512, JSON_THROW_ON_ERROR );
  14. return is_array ( $json_data ) ? $json_data : [];
  15. } catch ( JsonException $json_error ) {
  16. return [];
  17. }
  18. }
  19.  
  20. function GetInternetProtocol ( ) : string
  21. {
  22. $http_headers = [ 'HTTP_CF_CONNECTING_IP', 'HTTP_X_REAL_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP', 'REMOTE_ADDR' ];
  23.  
  24. foreach ( $http_headers as $header )
  25. {
  26. if ( empty ( $_SERVER [ $header ] ) )
  27. continue;
  28.  
  29. $ips = ( $header === 'HTTP_X_FORWARDED_FOR' ) ? explode ( ',', $_SERVER [ $header ] ) : [ $_SERVER [ $header ] ];
  30.  
  31. foreach ( $ips as $single_ip )
  32. {
  33. $single_ip = trim ( $single_ip );
  34.  
  35. if ( filter_var ( $single_ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) )
  36. return $single_ip;
  37. }
  38. }
  39.  
  40. return 'N/A';
  41. }
  42.  
  43. function WriteLog ( string $Event, array $data = [ ] ) : int
  44. {
  45. $baseDir = __DIR__ . '/manifest';
  46. $dayDir = $baseDir . '/' . date ( 'd-m-Y' );
  47.  
  48. if ( !is_dir ( $dayDir ) )
  49. mkdir ( $dayDir, 0775, true );
  50.  
  51. $safe_event = preg_replace ( '/[^a-z0-9_]+/i', '_', $Event );
  52. $file = $dayDir . '/manifest_' . $safe_event . '.json';
  53.  
  54. $fp = fopen ( $file, 'c+' );
  55.  
  56. if ( !$fp )
  57. return 0;
  58.  
  59. flock ( $fp, LOCK_EX );
  60.  
  61. $contents = stream_get_contents ( $fp );
  62. $logs = $contents ? SafeJSONDecode ( $contents ) : [ ];
  63. $redirectNumber = count ( $logs ) + 1;
  64. $entry = array_merge ( [ 'redirect_number' => $redirectNumber, 'timestamp' => date ( 'c' ), 'event' => $Event, 'ip' => $data [ 'ip' ] ?? GetInternetProtocol ( ) ], $data );
  65.  
  66. $logs [ ] = $entry;
  67.  
  68. rewind ( $fp );
  69. ftruncate ( $fp, 0 );
  70. fwrite ( $fp, json_encode ( $logs, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) );
  71. fflush ( $fp );
  72. flock ( $fp, LOCK_UN );
  73. fclose ( $fp );
  74.  
  75. return $redirectNumber;
  76. }
  77.  
  78. function Redirect ( string $link, int $delay, array $extra = [ ] ) : void
  79. {
  80. if ( !filter_var ( $link, FILTER_VALIDATE_URL ) )
  81. {
  82. http_response_code ( 400 );
  83. exit;
  84. }
  85.  
  86. $logData = array_merge ( [ 'ip' => GetInternetProtocol ( ), 'ua' => $_SERVER [ 'HTTP_USER_AGENT' ] ?? 'N/A', 'reason' => 'landing_redirect' ], $extra );
  87. $redirectNumber = logEvent ( 'landing_redirect', $logData );
  88.  
  89. if ( !headers_sent ( ) && $delay === 0 )
  90. header ( 'Location: ' . $link, true, 302 );
  91.  
  92. $escHTML = htmlspecialchars ( $link, ENT_QUOTES, 'UTF-8' );
  93. $escJS = json_encode ( $link ) ?: '""';
  94.  
  95. echo '<!doctype html><html><head><meta charset="utf-8"><meta name="robots" content="noindex, nofollow"><title>Redirecting...</title></head><body>';
  96.  
  97. if ( $delay > 0 )
  98. echo '<script>setTimeout(function(){location.replace(' . $escJS . ');}, ' . ( $delay * 1000 ) . ');</script>';
  99. else
  100. echo '<script>location.replace(' . $escJS . ');</script>';
  101.  
  102. echo '<noscript><a href="' . $escHTML . '">Continue</a></noscript></body></html>';
  103. exit;
  104. }
  105.  
  106.  
  107. require_once __DIR__ . '/geoip2.phar';
  108.  
  109. use GeoIp2\Database\Reader;
  110.  
  111. $ip = GetInternetProtocol ( );
  112. $country = 'N/A';
  113. $geo_source = 'none';
  114. $db_path = __DIR__ . '/geoip/GeoLite2-Country.mmdb';
  115.  
  116. try
  117. {
  118. if ( !file_exists ( $db_path ) )
  119. exit;
  120.  
  121. if ( !filter_var ( $ip, FILTER_VALIDATE_IP ) )
  122. {
  123. $country = 'N/A';
  124. $geo_source = 'N/A';
  125. }
  126. $reader = new Reader ( $db_path );
  127. $record = $reader->country ( $ip );
  128.  
  129. if ( !empty ( $record->country->isoCode ) )
  130. {
  131. $country = strtoupper ( $record->country->isoCode );
  132. $geo_source = 'local_mmdb';
  133. }
  134. }
  135.  
  136. catch ( Exception $Error )
  137. exit;
  138.  
  139.  
  140. $tier1 = [ 'US','GB','CA','AU','DE','FR','IT','ES','NL','SE','NO','DK','FI','IE','CH','AT','BE' ];
  141. $tier2 = [ 'RO','PL','HU','CZ','SK','PT','GR','BG','HR','SI','LT','LV','EE' ];
  142. $tier = in_array ( $country, $tier1 ) ? 'tier1' : ( in_array ( $country, $tier2 ) ? 'tier2' : 'tier3' );
  143. $delay = 2; // seconds in delay to redirect;
  144.  
  145. $smartlinks = [
  146. 'tier1' => [
  147. 'https://example.com',
  148. 'https://example1.com'
  149. ],
  150.  
  151. 'tier2' => [
  152. 'https://example.com',
  153. 'https://example1.com'
  154. ],
  155.  
  156. 'tier3' => [
  157. 'https://example.com',
  158. 'https://example1.com'
  159. ]
  160. ];
  161.  
  162. if ( !empty ( $smartlinks [ $tier ] ) )
  163. $linkToRedirect = $smartlinks [ $tier ] [ array_rand ( $smartlinks [ $tier ] ) ];
  164. else
  165. $linkToRedirect = 'https://fallback-link.com';
  166.  
  167.  
  168. Redirect ( $linkToRedirect, $delay, [ 'country' => $country, 'tier' => $tier, 'geo_source' => $geo_source ] );
  169.  
  170. ?>
Advertisement
Add Comment
Please, Sign In to add comment