Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- PHP Landing Manager
- (c) 2026 Alex Constantin aka LondoN eXtream
- Creator contact: https://steamcommunity.com/id/london_extreamcs
- */
- function SafeJSONDecode ( string $json_payload ): array
- {
- try
- {
- $json_data = json_decode ( $json_payload, true, 512, JSON_THROW_ON_ERROR );
- return is_array ( $json_data ) ? $json_data : [];
- } catch ( JsonException $json_error ) {
- return [];
- }
- }
- function GetInternetProtocol ( ) : string
- {
- $http_headers = [ 'HTTP_CF_CONNECTING_IP', 'HTTP_X_REAL_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP', 'REMOTE_ADDR' ];
- foreach ( $http_headers as $header )
- {
- if ( empty ( $_SERVER [ $header ] ) )
- continue;
- $ips = ( $header === 'HTTP_X_FORWARDED_FOR' ) ? explode ( ',', $_SERVER [ $header ] ) : [ $_SERVER [ $header ] ];
- foreach ( $ips as $single_ip )
- {
- $single_ip = trim ( $single_ip );
- if ( filter_var ( $single_ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) )
- return $single_ip;
- }
- }
- return 'N/A';
- }
- function WriteLog ( string $Event, array $data = [ ] ) : int
- {
- $baseDir = __DIR__ . '/manifest';
- $dayDir = $baseDir . '/' . date ( 'd-m-Y' );
- if ( !is_dir ( $dayDir ) )
- mkdir ( $dayDir, 0775, true );
- $safe_event = preg_replace ( '/[^a-z0-9_]+/i', '_', $Event );
- $file = $dayDir . '/manifest_' . $safe_event . '.json';
- $fp = fopen ( $file, 'c+' );
- if ( !$fp )
- return 0;
- flock ( $fp, LOCK_EX );
- $contents = stream_get_contents ( $fp );
- $logs = $contents ? SafeJSONDecode ( $contents ) : [ ];
- $redirectNumber = count ( $logs ) + 1;
- $entry = array_merge ( [ 'redirect_number' => $redirectNumber, 'timestamp' => date ( 'c' ), 'event' => $Event, 'ip' => $data [ 'ip' ] ?? GetInternetProtocol ( ) ], $data );
- $logs [ ] = $entry;
- rewind ( $fp );
- ftruncate ( $fp, 0 );
- fwrite ( $fp, json_encode ( $logs, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) );
- fflush ( $fp );
- flock ( $fp, LOCK_UN );
- fclose ( $fp );
- return $redirectNumber;
- }
- function Redirect ( string $link, int $delay, array $extra = [ ] ) : void
- {
- if ( !filter_var ( $link, FILTER_VALIDATE_URL ) )
- {
- http_response_code ( 400 );
- exit;
- }
- $logData = array_merge ( [ 'ip' => GetInternetProtocol ( ), 'ua' => $_SERVER [ 'HTTP_USER_AGENT' ] ?? 'N/A', 'reason' => 'landing_redirect' ], $extra );
- $redirectNumber = logEvent ( 'landing_redirect', $logData );
- if ( !headers_sent ( ) && $delay === 0 )
- header ( 'Location: ' . $link, true, 302 );
- $escHTML = htmlspecialchars ( $link, ENT_QUOTES, 'UTF-8' );
- $escJS = json_encode ( $link ) ?: '""';
- echo '<!doctype html><html><head><meta charset="utf-8"><meta name="robots" content="noindex, nofollow"><title>Redirecting...</title></head><body>';
- if ( $delay > 0 )
- echo '<script>setTimeout(function(){location.replace(' . $escJS . ');}, ' . ( $delay * 1000 ) . ');</script>';
- else
- echo '<script>location.replace(' . $escJS . ');</script>';
- echo '<noscript><a href="' . $escHTML . '">Continue</a></noscript></body></html>';
- exit;
- }
- require_once __DIR__ . '/geoip2.phar';
- use GeoIp2\Database\Reader;
- $ip = GetInternetProtocol ( );
- $country = 'N/A';
- $geo_source = 'none';
- $db_path = __DIR__ . '/geoip/GeoLite2-Country.mmdb';
- try
- {
- if ( !file_exists ( $db_path ) )
- exit;
- if ( !filter_var ( $ip, FILTER_VALIDATE_IP ) )
- {
- $country = 'N/A';
- $geo_source = 'N/A';
- }
- $reader = new Reader ( $db_path );
- $record = $reader->country ( $ip );
- if ( !empty ( $record->country->isoCode ) )
- {
- $country = strtoupper ( $record->country->isoCode );
- $geo_source = 'local_mmdb';
- }
- }
- catch ( Exception $Error )
- exit;
- $tier1 = [ 'US','GB','CA','AU','DE','FR','IT','ES','NL','SE','NO','DK','FI','IE','CH','AT','BE' ];
- $tier2 = [ 'RO','PL','HU','CZ','SK','PT','GR','BG','HR','SI','LT','LV','EE' ];
- $tier = in_array ( $country, $tier1 ) ? 'tier1' : ( in_array ( $country, $tier2 ) ? 'tier2' : 'tier3' );
- $delay = 2; // seconds in delay to redirect;
- $smartlinks = [
- 'tier1' => [
- 'https://example.com',
- 'https://example1.com'
- ],
- 'tier2' => [
- 'https://example.com',
- 'https://example1.com'
- ],
- 'tier3' => [
- 'https://example.com',
- 'https://example1.com'
- ]
- ];
- if ( !empty ( $smartlinks [ $tier ] ) )
- $linkToRedirect = $smartlinks [ $tier ] [ array_rand ( $smartlinks [ $tier ] ) ];
- else
- $linkToRedirect = 'https://fallback-link.com';
- Redirect ( $linkToRedirect, $delay, [ 'country' => $country, 'tier' => $tier, 'geo_source' => $geo_source ] );
- ?>
Advertisement
Add Comment
Please, Sign In to add comment