日期:2011-10-15  浏览次数:20531 次

  获取浏览器IP地址

  function getRemoteIPAddress() {

  $ip = $_SERVER['REMOTE_ADDR'];

  return $ip;

  }

 

  如果有代理服务器的情况下获取IP

  function getRealIPAddress() {

  if (!empty($_SERVER['HTTP_CLIENT_IP'])) { // check ip from share internet

  $ip = $_SERVER['HTTP_CLIENT_IP'];

  } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { // to check ip is pass from proxy

  $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];

  } else {

  $ip = $_SERVER['REMOTE_ADDR'];

  }

  return $ip;

  }

 

  获取 MySQL 时间戳

  $query = "select UNIX_TIMESTAMP(date_field) as mydate from mytable where 1=1";

  $records = mysql_query($query) or die(mysql_error());

  while($row = mysql_fetch_array($records)) {

  echo $row;

  }

 

  验证日期格式:YYYY-MM-DD

  function checkDateFormat($date) {

  // match the format of the date

  if (preg_match("/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/", $date, $parts)) {

  // check whether the date is valid of not

  if (checkdate($parts[2], $parts[3], $parts[1])) {

  return true;

  } else {

  return false;

  }

  } else {

  return false;

  }

  }

 

  重定向

  header('Location: http://www.php100.com');

 

  发送邮件

  $to = "someone@oschina.net";

  $subject = "Your Subject here";

  $body = "Body of your message here you can use HTML too. e.g.
Bold ";

  $headers = "From: You\r\n";

  $headers .= "Reply-To: info@yoursite.com\r\n";