drupal_valid_http_host

Definition

drupal_valid_http_host()
files/drupal-6.7/includes/bootstrap.inc, line 278

Description

Validate that $_SERVER['HTTP_HOST'] is safe.

As $_SERVER['HTTP_HOST'] is user input, ensure it only contains characters allowed in hostnames. See RFC 952 (and RFC 2181). $_SERVER['HTTP_HOST'] is lowercased.

Return value

TRUE if only containing valid characters, or FALSE otherwise.

Code

<?php
function drupal_valid_http_host() {
  $_SERVER['HTTP_HOST'] = strtolower($_SERVER['HTTP_HOST']);
  return preg_match('/^\[?(?:[a-z0-9-:\]_]+\.?)+$/', $_SERVER['HTTP_HOST']);
}
?>