Advertisement
rAthus

PHP load balancer between several subdomains

Dec 3rd, 2018
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.38 KB | None | 0 0
  1. $servers = array('s1','s2','s3'); // list of subdomains
  2.  
  3. $ip = $_SERVER['HTTP_CF_CONNECTING_IP']?:$_SERVER['REMOTE_ADDR'];
  4. $i = ((int)str_replace('.','',$ip))%count($servers);
  5. $server = $servers[$i];
  6. $server_current = array_shift((explode('.',$_SERVER['HTTP_HOST'])));
  7. if ($server_current!=$server)
  8.     /**/echo 'Wrong server!'; // replace this by a redirect to the correct location
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement