当前位置 : 主页 > 网络编程 > PHP >

common_inc_php

来源:互联网 收集:自由互联 发布时间:2021-06-30
1. [代码] [PHP]代码 ?phprequire "mysql.php";require "db.php";//数据库连接信息$db_host= "localhost";$db_name= "myccs"; $db_user= "root"; $db_pwd= "root";$db_charset = "gbk";db_connect($db_host ,$db_name ,$db_user ,$db_pwd,$db_char

1. [代码][PHP]代码    

<?php

	require "mysql.php";

	require "db.php";

	

//数据库连接信息

	$db_host	= "localhost";

	$db_name	= "myccs";  

	$db_user	= "root"; 

	$db_pwd	= "root";

	$db_charset = "gbk";

	db_connect($db_host ,$db_name ,$db_user ,$db_pwd,$db_charset);

	

	//设置路径常量

	define('DB_HOST', $db_host);

	define('DB_USER', $db_user);

	define('DB_PASSWORD', $db_pwd);

	define('DB_NAME', $db_name);

	

	$db = new DbClass();

	

	$sql = "SET NAMES 'gbk'";

	$db->query($sql);  





	//截取URL中的域名, 不包括前缀(子域名)

	function TrackDomain2($url)

	{

		

		$pattern = "/[\w-]+\.(com|net|org|gov|cc|biz|info|cn)(\.(cn|hk))*/";

		preg_match($pattern, $url, $matches);

		

		if(count($matches) > 0) 

		{

			return $matches[0];

		}else

		{

			$rs = parse_url($url);

			$main_url = $rs["host"];

			if(!strcmp(long2ip(sprintf("%u",ip2long($main_url))),$main_url)) 

			{

				return $main_url;

			}else

			{

				$arr = explode(".",$main_url);

				$count=count($arr);

				$endArr = array("com","net","org","3322");

				if (in_array($arr[$count-2],$endArr))

				{

					$domain = $arr[$count-3].".".$arr[$count-2].".".$arr[$count-1];

				}else

				{

					$domain =  $arr[$count-2].".".$arr[$count-1];

				}

				return $domain;

			}

		}

	}



?>
网友评论