设置twip noAuth REST API的使用权限

日期:2010-05-11 | 作者: Allen

上一篇文章中使用到了twip,文中用到的Twitter API是noAuth REST API,是不需要验证的,也就是说任何人都可以通过你架设的twip做一个自己的Twitter Widget,这无疑这个会给服务器带来一定的负担。

twip自带身份限制功能,既然如此,我们只要在开始请求noAuth REST API之前,使用身份限制功能即可。

以下是对index.php做了修改。

else if($isauth==='noauth'){
	//allenle:2010-05-10
	//only allowed_user can use noauth REST API
	$userid_start=strrpos($requesturl,"/");
	$userid_end=strrpos($requesturl,".");
	if($userid_start===false||$userid_end===false){
		header('HTTP/1.1 403 Forbidden');
		exit();
	}
	$userid=substr($requesturl,$userid_start+1,$userid_end-$userid_start-1);
	if(!userallowed($userid)){
		header('HTTP/1.1 403 Forbidden');
		exit();
	}
}

大概位置如下

修改后就能对noAuth REST API的访问进行身份限制了,关于如何使用twip的身份限制功能,请参看其Config.php。

也许你还会喜欢

2 Responses to “设置twip noAuth REST API的使用权限”

  1. 1 余波 五月 16th, 2010 at 7:32 下午

    你好,链接已经交换。

    回复

    Allen五月 16th, 2010 at 7:45 下午

    收到!

    回复

Leave a Reply

Additional comments powered by BackType