PHP_Depend
PHPCheckStyle
PHPSat
PHPMD
PHP_CodeSniffer
可以检查很多方面,比如说大括号风格,缩进风格,甚至还可以检查方法参数数量等等。实际使用时,可以搭配SVN钩子脚本,这样不符合要求的代码不允许提交,从而改善项目质量。
补充:我大概试用了一遍,如果是处于检测编码标准的目的的话,那么只有PHPCheckStyle,PHP_CodeSniffer比较合适,剩下的几个 基本是用于检测代码安全性,复杂度的,至于PHPCheckStyle,PHP_CodeSniffer的选择,PHPCheckStyle项目较新,配 置方便,但是不太稳定,比如说你的代码里有闭包的话,那么在检测大括号相应配置的时候很可能会误报,类似的问题还好几个,至于 PHP_CodeSniffer,项目时间较长,相对稳定,但是配置不够灵活。
Shell中的数组
声明数组的语法很简单,就是用小括号括起来:
$ foo=(a b)
访问数组元素的方法很也简单,唯一需要注意的就是大括号的使用:
$ echo ${foo[0]}
a
$ echo ${foo[1]}
b
如果想获得数组的长度,有如下两种方法:
$ echo ${#foo[*]}
2
$ echo ${#foo[@]}
2
Javascript CDN
Jquery是很多网站居家必备的Javascript类库,如果大家都使用CDN的话,无疑是非常低碳的!
jQuery CDN
Google Ajax API CDN
Microsoft CDN
用jQuery UI的话,则只有Google Ajax API CDN可用,还提供了theme的CDN,但是Google的服务有被墙的危险,所以Microsoft CDN也是必要的。
//将要处理的汉字,先由UTF8的汉字转成html实体形式再使用.
//示例代码:
$pic=imagecreate(250,30);
$black=imagecolorallocate($pic,0,0,0);
$white=imagecolorallocate($pic,255,255,255);
$font="C://WINDOWS//Fonts//simhei.ttf";$str = '中华人民共和国';
$str = mb_convert_encoding($str, "html-entities","utf-8" );//结 果:哪一队优先开球
imagettftext($pic,10,0,10,20,$white,$font,$str);
header("Content-type: image/jpeg");
$filename='./photo.jpg';
$im=imagecreatefromjpeg($filename);
imagecopymerge($im,$pic,0,0,0,0,250,30,50);
imagejpeg($im);
//pChart 示例代码:
/*
Example14: A smooth flat pie graph
*/
// Standard inclusions
header("content-type:text/html; charset=utf-8");
include_once("pChart/pData.class.php");
include_once("pChart/pChart.class.php");
// Dataset definition
$DataSet = new pData;
$DataSet->AddPoint(array(10,2,3,5,3),"Serie1");
$DataSet->AddPoint(iconv_arr(array("Jan","二月","三 月","Apr","May")),"Serie2");
$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie("Serie2");
// Initialise the graph
$Test = new pChart(300,200);
$Test->loadColorPalette("Sample/softtones.txt");
$Test->drawFilledRoundedRectangle(7,7,293,193,5,240,240,240);
$Test->drawRoundedRectangle(5,5,295,195,5,230,230,230);
// Draw the pie chart
$Test->setFontProperties("Fonts/simkai.ttf",8);
$Test->drawBasicPieGraph($DataSet->GetData(),$DataSet->GetDataDescription(),120,100,70,PIE_PERCENTAGE,255,255,218);
$Test->drawPieLegend(230,15,$DataSet->GetData(),$DataSet->GetDataDescription(),250,250,250);
$Test->Render("example14.png");
/*** 将文本由UTF8编码转化为数字形式编码(HTML实体)
* @param $arr 该参数可以为数组或者string
* @author Steven lxq70361@qq.com
*/
function iconv_arr($arr){
if(is_array($arr)){
foreach($arr as $k=>$v){
$arr[$k] = iconv_arr($v);
}
}else{
$arr = mb_convert_encoding($arr, "html-entities","utf-8" );
}
return $arr;
}
解决方法:
在PHP.INI里的 SOAP
[soap]
; Enables or disables WSDL caching feature.
; http://php.net/soap.wsdl-cache-enabled
soap.wsdl_cache_enabled=1
; Sets the directory name where SOAP extension will put cache files.
; http://php.net/soap.wsdl-cache-dir
soap.wsdl_cache_dir="d:\xampp\tmp"
; (time to live) Sets the number of second while cached file will be used
; instead of original one.
; http://php.net/soap.wsdl-cache-ttl
soap.wsdl_cache_ttl=86400
; Sets the size of the cache limit. (Max. number of WSDL files to cache)
soap.wsdl_cache_limit = 5
这里面配置Soap WSDL 缓存,这样就不会每次查询都要重新获取WSDL
在GBK字符集中,0xbf27不作为多字节字符,而0xbf5c是多字节字符。当0xbf和0x27组合后就变成0xbf27,0xbf 和0x5c 组合后就变成了0xbf5c 。
当注入字符比如0xbf27时,因为0x27为',所以addslashes()在27前加上5c(即\),把0xbf27修改为 0xbf5c27。而0xbf5c27的0xbf5c被认为时一个多字节字符,所以后面的27(')就被注入了sql语句中了。
代码如 下:
[client]
default-character-set=GBK
Create a table called users:
CREATE TABLE users
(
username VARCHAR(32) CHARACTER SET GBK,
password VARCHAR(32) CHARACTER SET GBK,
PRIMARY KEY (username)
);
<?php
$mysql = array();
$db = mysqli_init();
$db->real_connect('localhost', 'myuser', 'mypass', 'mydb');
$_POST['username'] = chr(0xbf) .
chr(0x27) .
' OR username = username /*';
$_POST['password'] = 'guess';
$mysql['username'] = addslashes($_POST['username']);
$mysql['password'] = addslashes($_POST['password']);
$sql = "SELECT *
FROM users
WHERE username = '{$mysql['username']}'
AND password = '{$mysql['password']}'";
$result = $db->query($sql);
if ($result->num_rows)
{
echo '<p>Success</p>';
}
else
{
echo '<p>Failure</p>';
}
?>
本文介绍的是用 mysql_real_escape_string对用户提交数据进行整理处理和通过addslashes以及mysql_escape_string这 3个类似的功能函数的区别。经过转义的数据可以直接插入到数据库中。
很好的说明了addslashes和 mysql_real_escape_string的区别,虽然国内很多PHP coder仍在依靠addslashes防止SQL注入(包括我在内),我还是建议大家加强中文防止SQL注入的检查。addslashes的问题在于黑 客可以用0xbf27来代替单引号,而addslashes只是将0xbf27修改为0xbf5c27,成为一个有效的多字节字符,其中的0xbf5c仍 会被看作是单引号,所以addslashes无法成功拦截。
当然addslashes也不是毫无用处,它是用于单字节字符串的处理,多字节字 符还是用mysql_real_escape_string吧。
另外对于php手册中get_magic_quotes_gpc的举例:
if (!get_magic_quotes_gpc()) {
$lastname = addslashes($_POST[‘lastname’]);
}
else {
$lastname = $_POST[‘lastname’];
}
最好对magic_quotes_gpc已经开放的情况下,还是 对$_POST[’lastname’]进行检查一下。
再说下mysql_real_escape_string和 mysql_escape_string这2个函数的区别:
mysql_real_escape_string 必须在(PHP 4 >= 4.3.0, PHP 5)的情况下才能使用。否则只能用 mysql_escape_string ,两者的区别是:
mysql_real_escape_string 考虑到连接的当前字符集,而mysql_escape_string 不考虑。
总结一 下:
addslashes() 是强行加;
mysql_real_escape_string() 会判断字符集,但是对PHP版本有要求;
mysql_escape_string不考虑连接的当前字符集
top.location.href=”url” 在顶层页面打开url(跳出框架)
self.location.href=”url” 仅在本页面打开url地址
parent.location.href=”url” 在父窗口打开Url地址
this.location.href=”url” 用法和self的用法一致
if (top.location == self.location) 判断当前location 是否为顶层来 禁止frame引用
如果页面当中有自定义的frame的话,也可以将parent self top换为自定义frame的名称
效果就是在自定义frame窗口打开url地址
引用:
这是一个简单的事例:
以下是top.htm 代码
<script language=javascript>
function rs(){
parent.left.location.href="top.htm"
parent.bot.location.href="top.htm"
}
</script>
<input type=button name=name value="ksdj" onclick=rs();>
以下是一个随意文件名的 htm文件:
<FRAMESET COLS="150,*">
<FRAME xsrc="left.htm" name=left>
<FRAMESET ROWS="150,*">
<FRAME xsrc="top.htm" name=top>
<FRAME xsrc="bot.htm" name=bot>
</FRAMESET>
</FRAMESET>
你 自己试试,我想你要的可能就是这样的效果!
我引用楼上老兄的方法回复,帮忙解释一下吧。
以下是top.htm 代码
<script language=javascript>
function rs(){
parent.left.location.href="top.htm" //partent指的是父页,也就是最外面的框架页,left只得是 left.htm,location是left页的一向对象,而href是location对象的一个属性,就是该属性确定了left的url地址。所以 这里就把你需要的地址给了这个parent.left。
parent.bot.location.href="top.htm" //此句意思同上面的大致一样。
} //函数结束,实现了同时对两个url的更新!
</script>
<input type=button name=name value="ksdj" onclick=rs();>
以下是一个随意文件名的 htm文件:
<FRAMESET COLS="150,*">
<FRAME xsrc="left.htm" name=left> > //给这个left.htm定义了一个名字叫left
<FRAMESET ROWS="150,*">
<FRAME xsrc="top.htm" name=top> //给这个top.htm定义了一个名字叫top
<FRAME xsrc="bot.htm" name=bot> //给这个bot.htm定义了一个名字叫bot
</FRAMESET>
</FRAMESET>
window 对象的 location 属性包含了当前页面的地址 (URL) 信息,你可以直接改变此属性值,将其设置成新的地址 (URL):
window.location = "http://www.yahoo.com";
或者
location = "http://www.yahoo.com";
你还可以通过下边的两种方法中的任何一种来使浏览器从服务器上下载 (Load) 页面:
reload() - 促使浏览器重新下载当前的页面,也就是“刷新”当前页面了。
replace(URL) - 促使浏览器根据 URL 参数中给出的地址 (URL) 下载页面,同时在当前浏览器存储的历史记录 (即所浏览过的页面的列表) 中使用新的地址(即此方法中的 URL 参数) 覆盖当前的页面。
使用 replace() 方法意味着用户将不能通过按 “返回” 按钮回到前边浏览过的那个页面,但这并不是说用户完全不能回到原来的所有页面,他们只不过是无法回到被 replace() 方法替换的那一个页面 (注意:只是被替换的那一个页面)。
framedemo.html,top.html,button.html为例来具体说明如何做
其中framedemo.html由上下两个页面组成,代码如下:
<frameset rows="50%,50%"><frame name=top xsrc="top.html"><frame name=button xsrc="button.html"></frameset>
现在假设top.html即上面的页面有一个button来实现对下面页面的刷新,可以用以下七种语句,哪个好用自己看着办了。
语句1. window.parent.frames[1].location.reload();
语句2. window.parent.frames.bottom.location.reload();
语句3. window.parent.frames["bottom"].location.reload();
语句4. window.parent.frames.item(1).location.reload();
语句5. window.parent.frames.item('bottom').location.reload();
语句6. window.parent.bottom.location.reload();
语句7. window.parent['bottom'].location.reload();
解释一下:
1.window指代的是当前页面,例如对于此例它指的是top.html页面。
2.parent指的是当前页面的父页面,也就是包含它的框架页面。例如对于此例它指的是framedemo.html。
3.frames是window对象,是一个数组。代表着该框架内所有子页面。
4.item是方法。返回数组里面的元素。
window.location是在当前frame中打开新页




