PHP»ñµÃµÄ¿Í»§¶ËºÍ·þÎñÆ÷¶ËIP
¿Í»§¶ËIPÏà¹ØµÄ±äÁ¿
1. $_SERVER['REMOTE_ADDR']; ¿Í»§¶ËIP£¬ÓпÉÄÜÊÇÓû§µÄIP£¬Ò²ÓпÉÄÜÊÇ´úÀíµÄIP¡£
2. $_SERVER['HTTP_CLIENT_IP']; ´úÀí¶ËµÄIP£¬¿ÉÄÜ´æÔÚ£¬¿ÉαÔì¡£
3. $_SERVER['HTTP_X_FORWARDED_FOR']; Óû§ÊÇÔÚÄĸöIPʹÓõĴúÀí£¬¿ÉÄÜ´æÔÚ£¬¿ÉÒÔαÔì¡£
·þÎñÆ÷¶ËIPÏà¹ØµÄ±äÁ¿
1. $SERVER_NAME£¬ÐèҪʹÓú¯Êýgethostbyname()»ñµÃ¡£Õâ¸ö±äÁ¿ÎÞÂÛÔÚ·þÎñÆ÷¶Ë»¹Êǿͻ§¶Ë¾ùÄÜÕýÈ·ÏÔʾ¡£
2. $HTTP_SERVER_VARS["SERVER_ADDR"]£¬ÔÚ·þÎñÆ÷¶Ë²âÊÔ£º127.0.0.1£¨Õâ¸öÓëhttpd.confÖÐBindAddressµÄÉèÖÃÖµÏà¹Ø£©¡£ÔÚ¿Í»§¶Ë²âÊÔ½á¹ûÕýÈ·¡£
3. $_SERVER['LOCAL_ADDR'] ¡¢$HTTP_SERVER_VARS['LOCAL_ADDR']£¬²âÊÔÖУ¬Î´»ñµÃÈκνá¹û£¨²âÊÔ»·¾³PHP5£©¡£
ÍêÕûµÄ»ñµÃIPÀà
class getIP{
function clientIP(){
$cIP = getenv('REMOTE_ADDR');
$cIP1 = getenv('HTTP_X_FORWARDED_FOR');
$cIP2 = getenv('HTTP_CLIENT_IP');
$cIP1 ? $cIP = $cIP1 : null;
$cIP2 ? $cIP = $cIP2 : null;
return $cIP;
}
function serverIP(){
return gethostbyname($_SERVER_NAME);
}
}
$getIP = new getIP();
$clientIp = getIP::clientIP();
$serverIp = getIP::serverIP();
echo 'Client IP is ',$clientIp,'<br />';
echo 'Server IP is ',$serverIp,'<br />';
Ïà¹ØÎĵµ£º
1.»ù±¾Àà
//smarty_config.php
<?php
define('TEMPLATE_DIR','templates/');
define('COMPILE_DIR','templates_c/');
define('CONFIG_DIR','configs/');
define('CACHE_DIR','cache/');
?>
//View.class.php
<?php
//ÅäÖÃÎļþ
require_once 'configs/smart_config.php';
//SmartyÀà
require('smarty/ ......
index.php:
$smarty = new Smarty;
$smarty->assign('Contacts',
array('555-222-9876',
'zaphod@slartibartfast.com',
array('555-444-3333',
'555-111-1234')));
$smarty->display('index.tpl');
index.tpl:
{$Contacts[0]}<br>
{$Contacts[1]}<br>
{* you can print arrays of arrays ......
index.php:
$smarty = new Smarty;
$smarty->assign('Contacts',
array('555-222-9876',
'zaphod@slartibartfast.com',
array('555-444-3333',
'555-111-1234')));
$smarty->display('index.tpl');
index.tpl:
{$Contacts[0]}<br>
{$Contacts[1]}<br>
{* you can print arrays of arrays ......
function FormatShowTime($nTotalSec)
{
//echo "total sec:" . $nTotalSec . '<br>';
$strTime = "";
//day
if ($nTotalSec > 3600 * 24)
{
$nDay = (int)($nTotalSec / (3600 * 24));
//$nDay > 0 ? $nDay : 1;
$strTime = $nDay;
$strTime .= 'Ìì';
//echo "nDay: ......
×ÛºÏÍøµêϵͳÊÇÓÉEÒ×ÍøÂç(68ws.cn)»ùÓÚphp+mysql¿ª·¢£¬¼æÈݸ÷ÀàÉÌÆ·µÄ·¢²¼¡¢Õ¹Ê¾ºÍ¶©¹º¡£³ýÁ˾ßÓÐÍêÉÆµÄÉÌÆ·ÀàÐ͹ÜÀí¡¢ÉÌÆ·¹ÜÀí¡¢ÅäËÍÖ§¸¶¹ÜÀí¡¢¶©µ¥¹ÜÀí¡¢»áÔ±·Ö×é¡¢»áÔ±¹ÜÀí¡¢²éѯͳ¼ÆºÍ¶àÏîÉÌÆ·´ÙÏú¹¦ÄÜ£¬»¹¾ßÓÐÍêÕûµÄÎÄÕ¡¢Í¼ÎÄ¡¢ÏÂÔØ¡¢µ¥Ò³¡¢¹ã¸æ·¢²¼µÈÍøÕ¾ÄÚÈݹÜÀí¹¦ÄÜ¡£ÏµÍ³¾ßÓо²Ì¬HTMLÉú³É¡¢UTF-8¶àÓïÑÔÖ§³ ......