Wordpress Addip Access Record

<?php

/*打开文件用于记录访问量,如果文件不存在自动创建*/
$counterFile = "counter.txt";

$fp = fopen($counterFile,"a+");

/*获取IP*/
$adress=$_SERVER["REMOTE_ADDR"]; 
							
/*统计访问量*/

$num = fgets($fp,5);

$num += 1;

print "您是第 "."$num"." 位访客,"." 您的IP是:["."$adress"."]";

/*关闭文件,重新以只写的方式打开*/
fclose($fp);
$fp=fopen($counterFile,"w");

/*更新变量$fp的值*/
fwrite($fp, $num);

fclose($fp);
							
?>	

[使用方法]

Copy code to WordPress’s Appearance ->[Themes Editor] ->[Footer.php Theme Footer File]
Let’s see how it works.

技术图片

2. Preservation of Visitors IP

[原码]

<?php

/*打开文件用于保存访客IP,如果文件不存在自动创建*/
$IPFile = "wp-IP.txt";

/*以追加方式打开文件*/
$fp = fopen($IPFile,"a");

/*获取访客IP*/
$adress=$_SERVER["REMOTE_ADDR"]; 

/*把IP写入文件*/
fwrite($fp, $adress);

/*界面美化和添加时间*/
fwrite($fp,"\r\n");
//date_default_timezone_set(PRC);
fwrite($fp,date("d-m-Y H:i:s"));
fwrite($fp,"\r\n");						
fwrite($fp,"#-----------------#");						
fwrite($fp,"\r\n");
							
//fclose($fp);

?>	

[使用方法]

Copy code to WordPress’s Appearance ->[Themes Editor] ->[Footer.php Theme Footer File]
Let’s see how it works.
技术图片

3. Use new page and add the code to the page

<--html-->
<a href="wp-IP.txt" target="show" rel="noopener noreferrer">IP访问记录</a>
<iframe name="show" id="show" width="300" height="500"/>
<--/html-->

4. Carnation tips

(1) The above two codes can be used separately or both, and it is suggested that they should be added otherwise only part II codes cannot be displayed on the website.

(2) The default time of acquisition in WordPress is 8 hours between Greenwich and Beijing, so a function should be added before the time statement is obtained

/Interface beautification and add time/

date_default_timezone_set(PRC);

Of these, the PRC represents the People ‘ s Republic of China.

In addition:
date_default_timezone_set(‘Asia/Shanghai’)
Singapore: Asia/Singapore
Continent: `Asia/Shanghai ‘ (Shanghai, Chongqing, Urumqi)
Hong Kong Taiwan region: Asia/Macao, Asia/Hong_Kong, Asia/Taipei (Hong Kong, Taipei)

未经允许不得转载:萌萌Apprentissage » Wordpress Addip Access Record

Like (0) 打赏

Comments 0

Protected with IP Blacklist CloudIP Blacklist Cloud
  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏

//下一个脚本特效
//下一个脚本