Aug 26
NerrWeb|PHP|MySQL|jQuery
好吧, 这是一个简易的Tweets页面, 应推友@lene_wf要求写了几个步骤, 实现的关键是你的WP主机要在国外, 或者或者….使用代理或是自建API之类的, 但这个不是讨论的重点.
页面的CSS copy了”中文推特圈”或是”rabr”, 额~~~~为什么是或? 说真的, 我的确不记得了~~~~~
1. 创建 一个WordPress Page, 取名为”Tweets”(当然,你可以根据需求命名)
2.下载Arc90的Full Twitter API client library written in PHP , 放在WP当前theme目录下面
3.修改WP当前theme的page.php, 在输出titel行下面(the_title();这行),加入如下代码:
php< ?php
if(the_title('','',false)=='Tweets'){
include('twitter.php');
}
?>
记得那个’Tweets’就是step 1中的页面名称.
4.下载下面的twitter.txt, 修改后缀名为.php, 然后编辑该脚本. 找到$tUsername和$tPassword, 修改为你的Twitter用户名和密码, 保存
5.Test, 如果没有意外应该可以在你WP的相应页面看到你的推了
效果参见: http://nerrsoft.com/tweets
我突然想, 要不要把它做成Plugin? 但好像意义不大. 那就算了吧. HOH
More
Aug 23
NerrWeb|PHP|MySQL|jQuery
今天的工作中遇到了一个问题, 用iframe将一个php脚本嵌入另一个页面, 提交脚本表单后Session出了问题, 似乎无法保存(Firefox或Chrome无此问题, 仅在IE环境下有问题).
使用session_id()查看后发现, 在IE下iframe内容更新后Session ID会随之发生变化, 也就是说原有的Session不再生效了, 当前的Session是全新并空的.
搜索Google后得到解决办法, 在PHP脚本输出内容之前加入一行header, 如下
php1
2
3
4
5
6
| <?php
header('P3P: CP="CAO PSA OUR"'); //ADD IN THIS LINE IN ORDER TO SOLVE THE INTERNET EXPLORER ALWAYS GET NEW SESSION ISSUE
session_start();
$_SESSION['test'] = 'anything';
echo $_SESSION['test'];
?> |
Aug 14
NerrWeb|PHP|MySQL|jQuery
自从Foursquare被墙之后一直用VPN上去checkin,虽说速度还不错,但每次都要先拨通VPN着实麻烦了点。
所以今天装了个支持API版的,试了下Google code上那个PHP版的代理,发现在nginx上要重写rewirte,索性在nginx上直接配个到api.foursquare.com的代理算了。
confserver {
listen 0.0.0.0:80;
server_name foursquare.yourdomainname.com;
#access_log /var/log/nginx/4sq.access_log;
#error_log /var/log/nginx/4sq.error_log info;
location / {
proxy_pass http://api.foursquare.com/;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
foursquare.yourdomainname.com根据情况自行设定
此配置仅用作手机端自定义API
Aug 11
NerrWeb|PHP|MySQL|jQuery
刚写了段代码, 主要功能是通过给定的网段信息(如10.0.0.1/22), 获取该网段的起始IP地址, 掩码IP地址和广播地址等的信息. 写这段代码的目的是做IP地址查询, 主要用于查询大型集团式企业日志服务器中成百上千个设备中的某一个是归属于哪一个分支企业的(分支企业按一定规则划分了不同的网段). 代码如下:
php1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
| <?php
/*
* Leon
* http://nerrsoft.com
* leon@nerrsoft.com
* 2010-08-11
*/
class ipInfo{
//根据给定的IP字串获取IP信息
public function getIpInfo($ipStr){
if(!$this->valid($ipStr)){
return false;
}
$ipArr = explode('/', $ipStr);
//information
$info['ipStr'] = $ipStr;
$info['bin']['mask'] = $this->getSubnetMask($ipArr[1]);
$info['ip']['mask'] = $this->bin2ip($info['bin']['mask']);
$info['long']['mask'] = ip2long($info['ip']['mask']);
$info['bin']['net'] = $this->ip2bin($ipArr[0]) & $info['bin']['mask'];
$info['ip']['net'] = $this->bin2ip($info['bin']['net']);
$info['long']['net'] = ip2long($info['ip']['net']);
$info['ip']['begin'] = long2ip($info['long']['net']+1);
$info['bin']['begin'] = $this->ip2bin($ipArr[0]);
$info['long']['begin'] = ip2long($info['ip']['begin']);
$info['ip']['end'] = long2ip(abs($info['long']['mask'])+$info['long']['begin']-3);
$info['bin']['end'] = $this->ip2bin($info['ip']['end']);
$info['long']['end'] = ip2long($info['ip']['end']);
$info['ip']['broacast'] = long2ip($info['long']['end']+1);
$info['bin']['broacast'] = $this->ip2bin($info['ip']['broacast']);
$info['long']['broacast'] = ip2long($info['ip']['broacast']);
return $info;
}
//验证IP字串格式有效性 10.0.0.1/24
private function valid($ipStr){
if(preg_match("/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\/\d{1,2}$/", $ipStr)){
return true;
}else{
return false;
}
}
//获取二进制
private function get_bin($number){
return str_pad(decbin($number),8,'0',STR_PAD_LEFT);
return decbin($number);
}
//IP地址转二进制
private function ip2bin($ip){
$ip_octets = split("\.", $ip);
unset($bin_sn);
foreach($ip_octets as $val){
$bin_sn[] = $this->get_bin($val);
}
return join(".", $bin_sn);
}
//二进制转IP地址
private function bin2ip($ip){
$ip_octets = split("\.", $ip);
unset($bin_sn);
foreach($ip_octets as $val){
$bin_sn[] = bindec($val);
}
return join(".", $bin_sn);
}
//获取子网掩码
private function getSubnetMask($mask){
for($i=1; $i<=32; $i++){
if($i<=$mask){
$maskStr .= '1';
}else{
$maskStr .= '0';
}
if($i%8==0){
$maskStr .= '.';
}
}
$maskStr = substr($maskStr, 0, -1);
return $maskStr;
}
}
//example
$ip = new ipInfo();
$result = $ip->getIpInfo('10.229.8.10/22');
print_r($result);
?> |
Jul 23
NerrWeb|PHP|MySQL|jQuery
前段时间因为项目需要在Ubuntu+Apache的环境下配置了基本Active Directory的Kerberos验证, 主要为了实现WEB应用基于AD的单点登陆SSO(即SingleSignOn).
下面将配置过程做简单记录:
0. 先说一下我的环境
Ubuntu9.04 + Apache2.2x + Win2k8 & AD
1. 因为Apache本身是不支持Kerberos的, 所以我们第一步是安装Kerberos Module for Apache即Mod_auth_kerb , 关于这个mod的文档资料和下载可以在官网找到. 在Ubuntu下不需要编译安装, 执行下面的apt-get搞定mod的安装. 安装后Apache的配置中会自动加载mod_auth_kerb.so, 不需要手工修改配置文件.
linux# sudo apt-get install libapache2-mod-auth-kerb
2. 装好Mod_auth_kerb后, 我们来对Kerberos进行配置, 编辑/etc/krb5.conf, 这里建议将原配置文件备份(cp /etc/krb5.conf /etc/krb5_bak.conf), 然后清空原配置文件内容, 贴入如下配置信息并按实际需求进行相应修改(default_realm, kdc, example.com).
More
Jun 28
NerrWeb|PHP|MySQL|jQuery
刚才写了个脚本,从google页面读取汇率,60秒更新一次,结果没更新几次就取不到数据了,开始也没想太多,但我回头再用google搜东西时杯具发生了,如下图…..
我还兴致勃勃的给旁边的同事看, 结果更悲剧, 他说他刚才google的时候也这情况, 不知原因……
额~~~~~~~~~~~~莫非公司内网都被影响了? 咳咳~~~~~低调处理~~~~~
下面是谷歌中国的截图
More
Older Entries