fork(1) download
  1. <?php
  2. function get_client($headers) {
  3. if (isset($headers['HTTP_X_FORWARDED_FOR'])) {
  4. return explode(', ', $headers['HTTP_X_FORWARDED_FOR'])[0];
  5. }
  6. else {
  7. return $_SERVER['REMOTE_ADDR'];
  8. }
  9. }
  10.  
  11. // $headers = getallheaders();
  12. $headers = array('HTTP_X_FORWARDED_FOR' => 'client, proxy1, proxy2');
  13. echo "Client 1: " . get_client($headers) . "\n";
  14.  
  15. $headers = array('HTTP_X_FORWARDED_FOR' => 'client');
  16. echo "Client 2: " . get_client($headers) . "\n";
  17.  
  18. $headers = array();
  19. echo "Client 3: " . get_client($headers) . "\n";
  20. ?>
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
Client 1: client
Client 2: client
Client 3: