根据访客所在城市ip地址自动跳转到分站的php代码
<?
//php教程获取ip的算法
$user_IP = ($_SERVER["HTTP_VIA"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : $_SERVER["REMOTE_ADDR"];
$user_IP = ($user_IP) ? $user_IP : $_SERVER["REMOTE_ADDR"];
//echo $user_IP;
//===================================
//
// 功能:IP地址获取真实地址函数
// 参数:$ip - IP地址
// 作者:[Discuz!] (C) Comsenz Inc.
//
//===================================
function convertip($ip) {
//IP数据文件路径,请根据情况自行修改
$dat_path = 'QQWry.dat';
//检查IP地址
if(!ereg("^([0-9]{1,3}.){3}[0-9]{1,3}$", $ip)){
return 'IP Address Error';
}
//打开IP数据文件
if(!$fd = @fopen($dat_path, 'rb')){
return 'IP date file not exists or access denied';
}
//分解IP进行运算,得出整形数
$ip = explode('.', $ip);
$ipNum = $ip[0] * 16777216 + $ip[1] * 65536 + $ip[2] * 256 + $ip[3];
//获取IP数据索引开始和结束位置
$DataBegin = fread($fd, 4);
$DataEnd = fread($fd, 4);
$ipbegin = implode('', unpack('L', $DataBegin));
if($ipbegin < 0) $ipbegin += pow(2, 32);
$ipend = implode('', unpack('L', $DataEnd));
if($ipend < 0) $ipend += pow(2, 32);
$ipAllNum = ($ipend - $ipbegin) / 7 + 1;
$BeginNum = 0;
$EndNum = $ipAllNum;
//使用二分查找法从索引记录中搜索匹配的IP记录
while($ip1num>$ipNum || $ip2num<$ipNum) {
$Middle= intval(($EndNum + $BeginNum) / 2);
//偏移指针到索引位置读取4个字节
fseek($fd, $ipbegin + 7 * $Middle);
$ipData1 = fread($fd, 4);
if(strlen($ipData1) < 4) {
fclose($fd);
return 'System Error';
}
//提取出来的数据转换成长整形,如果数据是负数则加上2的32次幂
$ip1num = implode('', unpack('L', $ipData1));
if($ip1num < 0) $ip1num += pow(2, 32);
//提取的长整型数大于我们IP地址则修改结束位置进行下一次循环
if($ip1num > $ipNum) {
$EndNum = $Middle;
continue;
}
//取完上一个索引后取下一个索引
$DataSeek = fread($fd, 3);
if(strlen($DataSeek) < 3) {
fclose($fd);
return 'System Error';
}
$DataSeek = implode('', unpack('L', $DataSeek.chr(0)));
fseek($fd, $DataSeek);
$ipData2 = fread($fd, 4);
if(strlen($ipData2) < 4) {
fclose($fd);
return 'System Error';
}
$ip2num = implode('', unpack('L', $ipData2));
if($ip2num < 0) $ip2num += pow(2, 32);
//没找到提示未知
if($ip2num < $ipNum) {
if($Middle == $BeginNum) {
fclose($fd);
return 'Unknown';
}
$BeginNum = $Middle;
}
}
//下面的代码读晕了,没读明白,有兴趣的慢慢读
$ipFlag = fread($fd, 1);
if($ipFlag == chr(1)) {
$ipSeek = fread($fd, 3);
if(strlen($ipSeek) < 3) {
fclose($fd);
return 'System Error';
}
$ipSeek = implode('', unpack('L', $ipSeek.chr(0)));
fseek($fd, $ipSeek);
$ipFlag = fread($fd, 1);
}
if($ipFlag == chr(2)) {
$AddrSeek = fread($fd, 3);
if(strlen($AddrSeek) < 3) {
fclose($fd);
return 'System Error';
}
$ipFlag = fread($fd, 1);
if($ipFlag == chr(2)) {
$AddrSeek2 = fread($fd, 3);
if(strlen($AddrSeek2) < 3) {
fclose($fd);
return 'System Error';
}
$AddrSeek2 = implode('', unpack('L', $AddrSeek2.chr(0)));
fseek($fd, $AddrSeek2);
} else {
fseek($fd, -1, SEEK_CUR);
}
while(($char = fread($fd, 1)) != chr(0))
$ipAddr2 .= $char;
$AddrSeek = implode('', unpack('L', $AddrSeek.chr(0)));
fseek($fd, $AddrSeek);
while(($char = fread($fd, 1)) != chr(0))
$ipAddr1 .= $char;
} else {
fseek($fd, -1, SEEK_CUR);
while(($char = fread($fd, 1)) != chr(0))
$ipAddr1 .= $char;
$ipFlag = fread($fd, 1);
if($ipFlag == chr(2)) {
$AddrSeek2 = fread($fd, 3);
if(strlen($AddrSeek2) < 3) {
fclose($fd);
return 'System Error';
}
$AddrSeek2 = implode('', unpack('L', $AddrSeek2.chr(0)));
fseek($fd, $AddrSeek2);
} else {
fseek($fd, -1, SEEK_CUR);
}
while(($char = fread($fd, 1)) != chr(0)){
$ipAddr2 .= $char;
}
}
fclose($fd);
//最后做相应的替换操作后返回结果
if(preg_match('/http/i', $ipAddr2)) {
$ipAddr2 = '';
}
$ipaddr = "$ipAddr1 $ipAddr2";
$ipaddr = preg_replace('/CZ88.Net/is', '', $ipaddr);
$ipaddr = preg_replace('/^s*/is', '', $ipaddr);
$ipaddr = preg_replace('/s*$/is', '', $ipaddr);
if(preg_match('/http/i', $ipaddr) || $ipaddr == '') {
$ipaddr = 'Unknown';
}
return $ipaddr;
}
?>
<script language="javascript教程">
var sf='<?echo convertip($user_IP);?>';
if(sf.indexOf("香港")>=0){
window.location.href="http://xianggang.111cn.net";
}
else if(sf.indexOf("广东省")>=0){
window.location.href="http://guangdong.111cn.net";
}
else if(sf.indexOf("北京")>=0){
window.location.href="http://beijing.111cn.net";
}
else{
window.location.href="http://www.111cn.net";
}
</script>
这是一个文件目录移动类,只要在listDir写你的要转移文件的目录名移就可以了,这个文件夹与文件移动类,比较适合采集下载的多文件操作,如要在打包文件里面加说明,等哦。
<?php教程
die();
class s{
//var $path ='flash';
var $htm ='/index.htm';
var $html='/index.html';
var $ladir='/111cn.net教程';
public function full_copy( $source, $target )
{
if ( is_dir( $source ) && $source != $source.$this->ladir )
{
@mkdir( $target );
$d = dir( $source );
while ( FALSE !== ( $entry = $d->read() ) )
{
if ( $entry == '.' || $entry == '..' )
{
continue;
}
$Entry = $source . '/' . $entry;
if ( is_dir( $Entry ) )
{
$this->full_copy( $Entry, $target . '/' . $entry );
continue;
}
copy( $Entry, $target . '/' . $entry );
}
$d->close();
}
else
{
copy( $source, $target );
}
}
//
public function listDir($dir_path)
{
if(is_dir($dir_path)){
if($dir_file=opendir($dir_path)){
while(($dir_list=readdir($dir_file))!==false)
{
if($dir_list!="." && $dir_list!="..")
{
$this->listSunDir($dir_path."/".$dir_list);
//$this->mkdir_r($dir_path."/".$dir_list.$this->ladir);
}
}
}else{
echo($dir_path);
}
}else{
echo($dir_path);
}
}
//
public function listSunDir($dir_path)
{
if(is_dir($dir_path)){
if($dir_file=opendir($dir_path)){
while(($dir_list=readdir($dir_file))!==false)
{
if($dir_list!="." && $dir_list!="..")
{
//$this->mkdir_r($dir_path."/".$dir_list.$this->ladir);
if( '/'.$dir_list == $this->ladir )
{
continue;
}
else
{
echo $dir_path."/".$dir_list,'<br />';
$this->full_copy($dir_path."/".$dir_list,$dir_path."/".$this->ladir);
$this->deldir($dir_path."/".$dir_list);
}
//$this->full_copy($dir_path."/".$dir_list,$dir_path."/".$dir_list.$this->ladir);
}
}
}else{
echo($dir_path);
}
}else{
echo($dir_path);
}
}
//
public function checkFile($dir)
{
if( is_dir( $dir ) )
{
if(is_file( $dir.$htm ) || is_file($dir . $html) )
{
continue;
}
else
{
$this->full_copy( $dir, $target );
}
}
}
// mkdir
function mkdir_r($dirName, $rights=0777)
{
$dirs = explode('/', $dirName);
$dir='';
foreach ($dirs as $part) {
$dir.=$part.'/';
if (!is_dir($dir) && strlen($dir)>0 && !is_file($dirName))
{
mkdir($dir, $rights);
echo "$dirName<br/>";
}
}
}
// delall
function deldir($dir)
{
if(is_dir($dir))
{
$rdir = $dir;
if($dirlist = scandir($rdir))
{
array_shift($dirlist);
array_shift($dirlist);
foreach($dirlist as $d){
$rd = $rdir.'/'.$d;
if(isset($d) && is_file($rd)){
unlink($rd);
}else{
$this->deldir($rd);
}
}
rmdir($rdir);
}else{
return false;
}
}
return true;
}
}
$s = new s();
$s->listDir('flash');//要移动目录
?>
<?php
require ('resize_img.php');
//how to use the class:
//makes a simple thumbnail of an image of 100x100 and saves the image then outputs it.
$imgresize = new resize_img();
$imgresize->sizelimit_x = 100;
$imgresize->sizelimit_y = 100;
$imgresize->keep_proportions = true;
$imgresize->output = 'PNG';
if( $imgresize->resize_image( 'C:/xampp/htdocs/wannabe/image_bin/public/treeshadows_001.gif' ) === false )
{
echo 'ERROR!';
}
else
{
$imgresize->save_resizedimage( 'C:/xampp/htdocs/wannabe/image_bin/public/thumbnails/', 'treeshadows_001' );
$imgresize->output_resizedimage();
}
$imgresize->destroy_resizedimage();
?>
// resize_img.php文件
<?php
/**
* by Daniel M. Story <admin@danstory.com>
*/
class resize_img
{
var $image_path = '';
//holds the image path
var $sizelimit_x = 250;
//the limit of the image width
var $sizelimit_y = 250;
//the limit of the image height
var $image_resource = '';
//holds the image resource
var $keep_proportions = true;
//if true it keeps教程 the image proportions when resized
var $resized_resource = '';
//holds the resized image resource
var $hasGD = false;
var $output = 'SAME';
//can be JPG, GIF, PNG, or SAME (same will save as old type)
function resize_img()
{
if( function_exists('gd_info') ){ $this->hasGD = true; }
}
function resize_image( $image_path )
{
if( $this->hasGD === false ){ return false; }
//no GD installed on the server!
list($img_width, $img_height, $img_type, $img_attr) = @getimagesize( $image_path );
//this is going to get the image width, height, and format
if( ( $img_width != 0 ) || ( $img_width != 0 ) )
//make sure it was loaded correctly
{
switch( $img_type )
{
case 1:
//GIF
$this->image_resource = @imagecreatefromgif( $image_path );
if( $this->output == 'SAME' ){ $this->output = 'GIF'; }
break;
case 2:
//JPG
$this->image_resource = @imagecreatefromjpeg( $image_path );
if( $this->output == 'SAME' ){ $this->output = 'JPG'; }
break;
case 3:
//PNG
$this->image_resource = @imagecreatefrompng( $image_path );
if( $this->output == 'SAME' ){ $this->output = 'PNG'; }
}
if( $this->image_resource === '' ){ return false; }
//it wasn't able to load the image
}
else{ return false; }
//something happened!
if( $this->keep_proportions === true )
{
if( ($img_width-$this->sizelimit_x) > ($img_height-$this->sizelimit_y) )
{
//if the width of the img is greater than the size limit we scale by width
$scalex = ( $this->sizelimit_x / $img_width );
$scaley = $scalex;
}
else
//if the height of the img is greater than the size limit we scale by height
{
$scalex = ( $this->sizelimit_y / $img_height );
$scaley = $scalex;
}
}
else
{
$scalex = ( $this->sizelimit_x / $img_width );
$scaley = ( $this->sizelimit_y / $img_height );
//just make the image fit the image size limit
if( $scalex > 1 ){ $scalex = 1; }
if( $scaley > 1 ){ $scaley = 1; }
//don't make it so it streches the image
}
$new_width = $img_width * $scalex;
$new_height = $img_height * $scaley;
$this->resized_resource = @imagecreatetruecolor( $new_width, $new_height );
//creates an image resource, with the width and height of the size limits (or new resized proportion )
if( function_exists( 'imageantialias' )){ @imageantialias( $this->resized_resource, true ); }
//helps in the quality of the image being resized
@imagecopyresampled( $this->resized_resource, $this->image_resource, 0, 0, 0, 0, $new_width, $new_height, $img_width, $img_height );
//resize the iamge onto the resized resource
@imagedestroy( $this->image_resource );
//destory old image resource
return true;
}
function save_resizedimage( $path, $name )
{
switch( strtoupper($this->output) )
{
case 'GIF':
//GIF
@imagegif( $this->resized_resource, $path . $name . '.gif' );
break;
case 'JPG':
//JPG
@imagejpeg( $this->resized_resource, $path . $name . '.jpg' );
break;
case 'PNG':
//PNG
@imagepng( $this->resized_resource, $path . $name . '.png' );
}
}
function output_resizedimage()
{
$the_time = time();
header('Last-Modified: ' . date( 'D, d M Y H:i:s', $the_time ) . ' GMT');
header('Cache-Control: public');
switch( strtoupper($this->output) )
{
case 'GIF':
//GIF
header('Content-type: image/gif');
@imagegif( $this->resized_resource );
break;
case 'JPG':
//JPG
header('Content-type: image/jpg');
@imagejpeg( $this->resized_resource );
break;
case 'PNG':
//PNG
header('Content-type: image/png');
@imagepng( $this->resized_resource );
}
}
function destroy_resizedimage()
{
@imagedestroy( $this->resized_resource );
@imagedestroy( $this->image_resource );
}
}
?>
现在我将告诉你如何看到有多少用户在浏览您的网站。有许多方法来显示它,但我试图保持它简单,干净。
首先,我们必须创建两个表,您的数据库教程。
CREATE TABLE `uonline` (
`session` varchar(100) NOT NULL,
`time` int(5) NOT NULL default '0'
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
这将创建两个表。一个是会议和其他的是时间。他们将我们的信息存储。
现在是PHP的时间。让我们一起创造我们的主要变数
<?php教程
session_start();
$ses = session_id();
$time = time();
$timech=$time-300;
session_start(); - This wills start a session
$ses = session_id(); - This will get our session's ID
$time = time(); - This will get the time
$timech=$time-300; - This will set our time to 5min
Now we have to connect to the database:
// Declare SQL login info
$host = "localhost";
$username = "";
$password = "";
$dbname = "";
// Now we are going to connect to our database
mysql教程_connect("$host", "$username", "$password")or die("<font style='color:red'><b>Can not connect:</b> ".mysql_error()."</font>");
mysql_select_db("$db_name")or die("<font style='color:red'><b>Can not select the database:</b> ".mysql_error()."</font>");
$host = "localhost"; - Your SQL's host name, usually it's "localhost"
$username = ""; - Your MySQL username
$password = ""; - Your MySQL password
$dbname = ""; - Your database's name
Now we have to look for existing sessions and get the number of sessions.
$result = mysql_query("SELECT * FROM uonline WHERE session='$ses'");
$num = mysql_num_rows($result);
$result = mysql_query("SELECT * FROM uonline WHERE session='$ses'"); - This will select all info from session column where it's value is "$ses"
$num = mysql_num_rows($result); - It will tell us how many active records are in session column
if($num == "0"){
$result1 = mysql_query("INSERT INTO uonline (session, time)VALUES('$ses', '$time')");
}else{
$result2 = mysql_query("UPDATE uonline SET time='$time' WHERE session = '$ses'");
}
if($num=="0"){ - If there's no records in session column then we must insert some records
$result1 = mysql_query("INSERT INTO uonline (session, time)VALUES('$ses', '$time')"); - Inserts session's ID and time to database
}else{ - But if there was more records than 0, let's update their records
$result2 = mysql_query("UPDATE uonline SET time='$time' WHERE session = '$ses'"); - Updates existing records
} - Ends If statement
Now let's find our info again from the columns:
$result3 = mysql_query("SELECT * FROM uonline");
$result3 = mysql_query("SELECT * FROM uonline"); - This will get all info from uonline table
It's time for showing how many users are looking your site:
$usersonline = mysql_num_rows($result3);
echo "There are: <b>".$usersonline."</b> users online";
$usersonline = mysql_num_rows($result3); - It will get the number of records in columns
echo "There are: <b>".$usersonline."</b> users online"; - This will show how many users are on your site
When the users have left, you must delete their records from database.
mysql_query("DELETE FROM uonline WHERE time<$timech");
?>
mysql_query("DELETE FROM uonline WHERE time<$timech"); - Deletes records from database when 5min has been thru.
And here's the full code:
<?php
session_start();
$ses = session_id();
$time = time();
$timech=$time-300;
$host = "localhost";
$username = "";
$password = "";
$dbname = "";
mysql_connect("$host", "$username", "$password")or die("<font style='color:red'><b>Can not connect:</b> ".mysql_error()."</font>");
mysql_select_db("$db_name")or die("<font style='color:red'><b>Can not select the database:</b> ".mysql_error()."</font>");
$result = mysql_query("SELECT * FROM uonline WHERE session='$ses'");
$num = mysql_num_rows($result);
if($num == "0"){
$result1 = mysql_query("INSERT INTO uonline (session, time)VALUES('$ses', '$time')");
}else{
$result2 = mysql_query("UPDATE uonline SET time='$time' WHERE session = '$ses'");
}
$result3 = mysql_query("SELECT * FROM uonline");
$usersonline = mysql_num_rows($result3);
echo "There are: <b>".$usersonline."</b> users online";
mysql_query("DELETE FROM uonline WHERE time<$timech");
?>
此脚本时,页面最后修订和产出作为二十分钟前,或XX天前的日期...或者即使您不更新太多 - 二十周前显示!
//File Name
$last_modified = filemtime("FILE.php");
{
$timediff = time() - $last_modified;
if ($timediff < 3600)
{
if ($timediff < 120)
{
$returndate = "1 minute ago.";
}
else
{
$returndate = intval($timediff / 60) . " minutes ago.";
}
}
else if ($timediff < 7200)
{
$returndate = "1 hour ago.";
}
else if ($timediff < 86400)
{
$returndate = intval($timediff / 3600) . " hours ago.";
}
else if ($timediff < 172800)
{
$returndate = "1 day ago.";
}
else if ($timediff < 604800)
{
$returndate = intval($timediff / 86400) . " days ago.";
}
else if ($timediff < 1209600)
{
$returndate = "1 week ago.";
}
else if ($timediff < 3024000)
{
$returndate = intval($timediff / 604900) . " weeks ago.";
}
else
{
$returndate = @date('n-j-Y', $timestamp);
if($type=="fulldate")
{
$returndate = @date('n-j-y, H:i', $timestamp);
}
else if ($type=="time")
{
$returndate = @date('H:i', $timestamp);
}
}
//Display It
print("Last Modified: ");
print($returndate);
}
?>
它应该很容易理解。
$ last_modified = filemtime(“FILE.php”); - 更改FILE.php到文件您要连接。
相关文章
- 有一种方法,可以不打开网站而直接查看到这个网站的源代码.. 这样可以有效地防止误入恶意网站... 在浏览器地址栏输入: view-source:http://...2016-09-20
- <?php require('path.inc.php'); header('content-Type: text/html; charset=utf-8'); $borough_id = intval($_GET['id']); if(!$borough_id){ echo ' ...2016-11-25
- 本文实例讲述了JS基于Mootools实现的个性菜单效果代码。分享给大家供大家参考,具体如下:这里演示基于Mootools做的带动画的垂直型菜单,是一个初学者写的,用来学习Mootools的使用有帮助,下载时请注意要将外部引用的mootools...2015-10-23
- 本文实例讲述了JS+CSS实现分类动态选择及移动功能效果代码。分享给大家供大家参考,具体如下:这是一个类似选项卡功能的选择插件,与普通的TAb区别是加入了动画效果,多用于商品类网站,用作商品分类功能,不过其它网站也可以用,...2015-10-21
- 本文实例讲述了JS实现自定义简单网页软键盘效果。分享给大家供大家参考,具体如下:这是一款自定义的简单点的网页软键盘,没有使用任何控件,仅是为了练习JavaScript编写水平,安全性方面没有过多考虑,有顾虑的可以不用,目的是学...2015-11-08
- php 取除连续空格与换行代码,这些我们都用到str_replace与正则函数 第一种: $content=str_replace("n","",$content); echo $content; 第二种: $content=preg_replac...2016-11-25
- php简单用户登陆程序代码 这些教程很对初学者来讲是很有用的哦,这款就下面这一点点代码了哦。 <center> <p> </p> <p> </p> <form name="form1...2016-11-25
- 公司一些wordpress网站由于下载的插件存在恶意代码,导致整个服务器所有网站PHP文件都存在恶意代码,就写了个简单的脚本清除。恶意代码示例...2015-10-23
- 其实挺简单的就是if(navigator.userAgent.indexOf('UCBrowser') > -1) {alert("uc浏览器");}else{//不是uc浏览器执行的操作}如果想测试某个浏览器的特征可以通过如下方法获取JS获取浏览器信息 浏览器代码名称:navigator...2015-11-08
- 本文实例讲述了JS实现双击屏幕滚动效果代码。分享给大家供大家参考,具体如下:这里演示双击滚屏效果代码的实现方法,不知道有觉得有用处的没,现在网上还有很多还在用这个特效的呢,代码分享给大家吧。运行效果截图如下:在线演...2015-10-30
- 一、日期减去天数等于第二个日期function cc(dd,dadd){//可以加上错误处理var a = new Date(dd)a = a.valueOf()a = a - dadd * 24 * 60 * 60 * 1000a = new Date(a)alert(a.getFullYear() + "年" + (a.getMonth() +...2015-11-08
- 微信支付,即便交了保证金,你还是处理测试阶段,不能正式发布。必须到你通过程序测试提交订单、发货通知等数据到微信的系统中,才能申请发布。然后,因为在微信中是通过JS方式调用API,必须在微信后台设置支付授权目录,而且要到...2014-05-31
- 本文实例讲述了PHP常用的小程序代码段。分享给大家供大家参考,具体如下:1.计算两个时间的相差几天$startdate=strtotime("2009-12-09");$enddate=strtotime("2009-12-05");上面的php时间日期函数strtotime已经把字符串...2015-11-24
- 小编分享了一段简单的php中文转拼音的实现代码,代码简单易懂,适合初学php的同学参考学习。 代码如下 复制代码 <?phpfunction Pinyin($_String...2017-07-06
php导出csv格式数据并将数字转换成文本的思路以及代码分享
php导出csv格式数据实现:先定义一个字符串 存储内容,例如 $exportdata = '规则111,规则222,审222,规222,服2222,规则1,规则2,规则3,匹配字符,设置时间,有效期'."/n";然后对需要保存csv的数组进行foreach循环,例如复制代...2014-06-07- ecshop商品无限级分类代码 function cat_options($spec_cat_id, $arr) { static $cat_options = array(); if (isset($cat_options[$spec_cat_id]))...2016-11-25
- 本文介绍了如何延迟javascript代码的加载,加快网页的访问速度。 当一个网站有很多js代码要加载,js代码放置的位置在一定程度上将会影像网页的加载速度,为了让我们的网页加载速度更快,本文总结了一下几个注意点...2013-10-13
- 这篇文章主要介绍了vue项目,代码提交至码云,iconfont的用法说明,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-07-30
- 这篇文章主要介绍了IDEA插件之快速删除Java代码中的注释,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2021-02-18
- 这篇文章主要介绍了C#超实用代码段合集,涉及C#针对图标、数学运算、拼音、日期、时间及文件夹等的相关操作技巧,需要的朋友可以参考下...2020-06-25