色一情一乱一伦一区二区三区,亚洲欧洲精品一区二区三区波多野 ,男女后进式猛烈xx00动态图片 http://www.86956464.com/blog 中山php|最優(yōu)網(wǎng)絡(luò) Mon, 13 May 2013 04:56:43 +0000 en hourly 1 http://wordpress.org/?v=3.1.4 php壓縮html : 清除換行符,清除制表符,去掉注釋標(biāo)記 http://www.86956464.com/blog/view-431.html http://www.86956464.com/blog/view-431.html#comments Sat, 30 Mar 2013 06:48:24 +0000 lin http://www.86956464.com/blog/?p=431 /**
* 壓縮html : 清除換行符,清除制表符,去掉注釋標(biāo)記
* @param $string
* @return 壓縮后的$string
* */
function compress_html($string) {
$string = str_replace("\r\n", '', $string); //清除換行符
$string = str_replace("\n", '', $string); //清除換行符
$string = str_replace("\t", '', $string); //清除制表符
$pattern = array (
"/> *([^ ]*) *</", //去掉注釋標(biāo)記
"/[\s]+/",
"/<!--[^!]*-->/",
"/\" /",
"/ \"/",
"'/\*[^*]*\*/'"
);
$replace = array (
">\\1<",
" ",
"",
"\"",
"\"",
""
);
return preg_replace($pattern, $replace, $string);
}

]]>
http://www.86956464.com/blog/view-431.html/feed 689
php防止刷流量攻擊 http://www.86956464.com/blog/view-428.html http://www.86956464.com/blog/view-428.html#comments Fri, 29 Mar 2013 10:55:10 +0000 lin http://www.86956464.com/blog/?p=428 <?php
//查詢禁止IP
$ip =$_SERVER['REMOTE_ADDR'];
$fileht=".htaccess2";
if(!file_exists($fileht))file_put_contents($fileht,"");
$filehtarr=@file($fileht);
if(in_array($ip."\r\n",$filehtarr))die("Warning:"."<br>"."Your IP address are forbided by some reason, IF you have any question Pls emill to shop@mydalle.com!");

//加入禁止IP
$time=time();
$fileforbid="log/forbidchk.dat";
if(file_exists($fileforbid))
{ if($time-filemtime($fileforbid)>60)unlink($fileforbid);
else{
$fileforbidarr=@file($fileforbid);
if($ip==substr($fileforbidarr[0],0,strlen($ip)))
{
if($time-substr($fileforbidarr[1],0,strlen($time))>600)unlink($fileforbid);
elseif($fileforbidarr[2]>600){file_put_contents($fileht,$ip."\r\n",FILE_APPEND);unlink($fileforbid);}
else{$fileforbidarr[2]++;file_put_contents($fileforbid,$fileforbidarr);}
}
}
}
//防刷新
$str="";
$file="log/ipdate.dat";
if(!file_exists("log")&&!is_dir("log"))mkdir("log",0777);
if(!file_exists($file))file_put_contents($file,"");
$allowTime = 120;//防刷新時(shí)間
$allowNum=10;//防刷新次數(shù)
$uri=$_SERVER['REQUEST_URI'];
$checkip=md5($ip);
$checkuri=md5($uri);
$yesno=true;
$ipdate=@file($file);
foreach($ipdate as $k=>$v)
{ $iptem=substr($v,0,32);
$uritem=substr($v,32,32);
$timetem=substr($v,64,10);
$numtem=substr($v,74);
if($time-$timetem<$allowTime){
if($iptem!=$checkip)$str.=$v;
else{
$yesno=false;
if($uritem!=$checkuri)$str.=$iptem.$checkuri.$time."1\r\n";
elseif($numtem<$allowNum)$str.=$iptem.$uritem.$timetem.($numtem+1)."\r\n";
else
{
if(!file_exists($fileforbid)){$addforbidarr=array($ip."\r\n",time()."\r\n",1);file_put_contents($fileforbid,$addforbidarr);}
file_put_contents("log/forbided_ip.log",$ip."--".date("Y-m-d H:i:s",time())."--".$uri."\r\n",FILE_APPEND);
$timepass=$timetem+$allowTime-$time;
die("Warning:"."<br>"."Sorry,you are forbided by refreshing frequently too much, Pls wait for ".$timepass." seconds to continue!");
}
}
}
}
if($yesno) $str.=$checkip.$checkuri.$time."1\r\n";
file_put_contents($file,$str);

]]>
http://www.86956464.com/blog/view-428.html/feed 0
php多維數(shù)組的搜索 http://www.86956464.com/blog/view-425.html http://www.86956464.com/blog/view-425.html#comments Mon, 17 Dec 2012 12:48:04 +0000 lin http://www.86956464.com/blog/?p=425 1 php搜索多維數(shù)組的鍵值

如下面例子:

$foo[1]['a']['xx'] = 'bar 1';
$foo[1]['b']['xx'] = 'bar 2';
$foo[2]['a']['bb'] = 'bar 3';
$foo[2]['a']['yy'] = 'bar 4';
$foo[3]['c']['dd'] = 'bar 3';
$foo[3]['f']['gg'] = 'bar 3';
$foo['info'][1] = 'bar 5';

如果要查找 bar 3 怎么進(jìn)行查找呢。有三個(gè)結(jié)果,而這三個(gè)結(jié)果都要,看下面的函數(shù):
-------------------------------------------------------------------------------------------------------------------------------
function array_search_re($needle, $haystack, $a=0, $nodes_temp=array()){
global $nodes_found;
$a++;
foreach ($haystack as $key1=>$value1) {
??? $nodes_temp[$a] = $key1;
??? if (is_array($value1)){???
????? array_search_re($needle, $value1, $a, $nodes_temp);
??? }
??? else if ($value1 === $needle){
????? $nodes_found[] = $nodes_temp;
??? }
}
return $nodes_found;
}
---------------------------------------------------------------------------------------------------------------------------------
這個(gè)函數(shù)就可以把上面要查找到的內(nèi)容全部返回出鍵名來
$result = array_search_re('bar 3', $foo);

print_r($result);

輸出結(jié)果為如下:
Array ( [0] => Array ( [1] => 2 [2] => a [3] => bb )
?????? ?? [1] => Array ( [1] => 3 [2] => c [3] => dd )
?????? ?? [2] => Array ( [1] => 3 [2] => f [3] => gg )
???? ?? )

1 php搜索多維數(shù)組的鍵名

function array_search_key($needle, $haystack){
global $nodes_found;

foreach ($haystack as $key1=>$value1) {
?
?if ($key1=== $needle){
?
??$nodes_found[] = $value1;
???????
?? }
??? if (is_array($value1)){???
????? array_search_key($needle, $value1);
??? }
???
???
}

return $nodes_found;
}
$result = array_search_key('a', $foo);

print_r($result);

輸出結(jié)果為如下:
?

Array
(
??? [0] => Array
??????? (
??????????? [xx] => bar 1
??????? )

??? [1] => Array
??????? (
??????????? [bb] => bar 3
??????? )

??? [2] => Array
??????? (
??????????? [yy] => bar 4
??????? )

)

]]>
http://www.86956464.com/blog/view-425.html/feed 743
php過濾客戶提交參數(shù),防注入 http://www.86956464.com/blog/view-417.html http://www.86956464.com/blog/view-417.html#comments Sat, 24 Nov 2012 09:16:40 +0000 lin http://www.86956464.com/blog/?p=417 以下代碼實(shí)現(xiàn)過濾php的$_GET 和$_POST參數(shù)

/**
* 安全防范
*/
function Add_S($array)
{
foreach($array as $key=>$value)
{
if(!is_array($value))
{
$value = get_magic_quotes_gpc()?$value:addslashes($value);
$array[$key]=filterHtml($value);
}
Else
{
Add_S($array[$key]);
}
}
return $array;
}
function glstr($var) {

if (is_array($var)) {
return Add_S($var);
}
elseif(strlen($var)){
$var = get_magic_quotes_gpc()?$var:addslashes($var);

$var = filterHtml($var);
}
return $var;
}
function filterHtml($html)
{
$farr = array(
"/<!DOCTYPE([^>]*?)>/eis",
"/<(\/?)(html|body|head|link|meta|base|input)([^>]*?)>/eis",
"/<(script|i?frame|style|title|form)(.*?)<\/\\1>/eis",
"/(<[^>]*?\s+)on[a-z]+\s*?=(\"|')([^\\2]*)\\2([^>]*?>)/isU",//過濾javascript的on事件
"/\s+/",//過濾多余的空白
);
$tarr = array(
"",
"",
"",
"\\1\\4",
" ",
);
$html = preg_replace( $farr,$tarr,$html);
return $html;
}
if (sizeof($_GET)) {
foreach($_GET as $key => $value) {
$_GET[$key] = glstr($value); //
}

}
if (sizeof($_POST)) {
foreach($_POST as $key => $value) {
$_POST[$key] = glstr($value); //
}
}

]]>
http://www.86956464.com/blog/view-417.html/feed 343
php計(jì)算代碼運(yùn)行時(shí)間和使用內(nèi)存 http://www.86956464.com/blog/view-415.html http://www.86956464.com/blog/view-415.html#comments Wed, 14 Nov 2012 08:28:49 +0000 lin http://www.86956464.com/blog/?p=415

<?php

//開始計(jì)時(shí)


$HeaderTime =
microtime(true);//參數(shù)true表示返回浮點(diǎn)數(shù)值

//代碼

//...

printf(" total run: %.2f s<br>".
"memory usage: %.2f M<br> ",
microtime(true)-$HeaderTime,
memory_get_usage() / 1024 / 1024 );
?>
結(jié)果:

total runtime: 1.47 s

memory usage: 77.09 M

]]>
http://www.86956464.com/blog/view-415.html/feed 454
smarty模版使用php標(biāo)簽,如何獲取模版變量 http://www.86956464.com/blog/view-409.html http://www.86956464.com/blog/view-409.html#comments Sat, 22 Sep 2012 03:54:23 +0000 lin http://www.86956464.com/blog/?p=409 已經(jīng)assign一個(gè)模版變量$assign,由于要做特殊的循環(huán)輸出,使用for循環(huán),因此使用到了php標(biāo)簽,但是php語句和模版語句的變量作用域是不同的,因此不能直接獲取到

{{php}}

for($i=0;$i<count($assign);$i=$i+2){
echo '
<ul>
<li> <span class="zz_pic"><a href="'._url('picture',array('col_key'=>'cert','pic_id'=>$assign[$i][pic_id])).'" title=""><img src="uploads/thumb_'.$assign[$i][pic].'" alt=""></a></span> <span class="zz_title"><a href="'._url('picture',array('col_key'=>'cert','pic_id'=>$assign[$i][pic_id])).'" title="">'.$assign[$i][title].'</a></span> </li>
<li> <span class="zz_pic"><a href="'._url('picture',array('col_key'=>'cert','pic_id'=>$assign[$i+1][pic_id])).'" title=""><img src="uploads/thumb_'.$assign[$i+1][pic].'" alt=""></a></span> <span class="zz_title"><a href="'._url('picture',array('col_key'=>'cert','pic_id'=>$assign[$i+1][pic_id])).'" title="">'.$assign[$i+1][title].'</a></span> </li>i>

</ul>';}
{{/php}}

解決的方法是:模版變量全部存在smarty的一個(gè)對(duì)象里面;只要在for之前進(jìn)行賦值:$assign = $this->_tpl_vars[assign];

{{php}}
$assign = $this->_tpl_vars[assign];
for($i=0;$i<count($assign);$i=$i+2){
echo '
<ul>
<li> <span class="zz_pic"><a href="'._url('picture',array('col_key'=>'cert','pic_id'=>$assign[$i][pic_id])).'" title=""><img src="uploads/thumb_'.$assign[$i][pic].'" alt=""></a></span> <span class="zz_title"><a href="'._url('picture',array('col_key'=>'cert','pic_id'=>$assign[$i][pic_id])).'" title="">'.$assign[$i][title].'</a></span> </li>
<li> <span class="zz_pic"><a href="'._url('picture',array('col_key'=>'cert','pic_id'=>$assign[$i+1][pic_id])).'" title=""><img src="uploads/thumb_'.$assign[$i+1][pic].'" alt=""></a></span> <span class="zz_title"><a href="'._url('picture',array('col_key'=>'cert','pic_id'=>$assign[$i+1][pic_id])).'" title="">'.$assign[$i+1][title].'</a></span> </li>i>

</ul>';}
{{/php}}

]]>
http://www.86956464.com/blog/view-409.html/feed 502
好用的smarty標(biāo)簽:capture,literal,fetch http://www.86956464.com/blog/view-407.html http://www.86956464.com/blog/view-407.html#comments Sat, 22 Sep 2012 03:16:24 +0000 lin http://www.86956464.com/blog/?p=407

1,capture標(biāo)簽

capture的中文意思是抓取,它的作用是抓取模板輸出的數(shù)據(jù),當(dāng)我們需要它的時(shí)候,調(diào)用它,以得到抓取數(shù)據(jù)的目的。例子:

  1. {capture?name=test}
  2. <img?src=”testimg.jpg”>
  3. {/capture}
  4. <div?class=”image”>
  5. {$smarty.capture.test}
  6. </div>

說明:
在{capture name=”test”}和{/capture}之間的內(nèi)容被存儲(chǔ)到變量$test中,該變量由name屬性指定.在模板中通過 $smarty.capture.test 訪問該變量.如果沒有指定name 屬性,函數(shù)默認(rèn)將使用”default” 作為參數(shù),這一點(diǎn)很jquery中的clone

2,config_load標(biāo)簽

config_load可以直接將文件中的內(nèi)容讀取出來,這樣可以省掉assign這一步。

  1. test.csv:
  2. pageTitle?=?”config_load_test”
  3. bodyBgColor?=?”#eeeeee”
  4. img?=?”girl.jpg”
  5. width=”100″
  6. height=”100″
  7. index.tpl:
  8. {config_load?file=”test.csv”}
  9. <html>
  10. <title>{#pageTitle#}</title>
  11. <body?bgcolor=”{#bodyBgColor#}”>
  12. <img?src=”{#img#}”?width=”{#width#}”?height=”{#height#}”>
  13. </body>
  14. </html>

上述過程中如果出現(xiàn)這樣的問題Warning: Smarty error: unable to read resource, 請(qǐng)查看一下,你的test.csv是不是放在smarty的配置目錄中,默認(rèn)配置目錄是configs

  1. /**
  2. *?The?directory?where?config?files?are?located.
  3. *
  4. *?@var?string
  5. */
  6. var?$config_dir??????=??’configs’;

3,literal標(biāo)簽的使用

做web開發(fā),難免會(huì)寫一些JS,jquery代碼。js和jquery里面都會(huì){}這樣的符號(hào),smarty會(huì)不會(huì)把它理解成php的變量呢?如果你不加literal標(biāo)簽的話,smarty肯定會(huì)把它理解變量了,加了就不會(huì),例如:

  1. {literal}
  2. function?getAbsLeft(e){
  3. var?l=e.offsetLeft;
  4. while(e=e.offsetParent)l+=e.offsetLeft;
  5. return?l;
  6. }
  7. function?getAbsTop(e){
  8. var?t=e.offsetTop;
  9. while(e=e.offsetParent)t+=e.offsetTop;
  10. return?t;
  11. }
  12. {/literal}

4,php標(biāo)簽

當(dāng)你習(xí)慣了assign后,你有沒有想過,在模板文件里面直接寫php代碼呢,我想有的時(shí)候你肯定很想吧。例如:

  1. {php}
  2. global?$result;
  3. foreach($result?as?$key=>$value){
  4. echo?”key=$key,value=>$value<br>”;
  5. }
  6. {/php}

5,strip標(biāo)簽

strip標(biāo)簽去除標(biāo)簽內(nèi)的空格和回車,這一點(diǎn)我覺得,做手機(jī)開發(fā)的朋友肯定用的到,因?yàn)槿强崭裼锌赡軙?huì)導(dǎo)致整個(gè)頁面錯(cuò)亂,甚至是一個(gè)空白頁面。手機(jī)屏幕小,估計(jì)用smarty的可能性也比較小。

  1. {strip}
  2. <div>
  3. <font?color=”red”>strip</font>
  4. </div>
  5. {/strip}

6,fetch標(biāo)簽

fetch標(biāo)簽根php的file_get_contents挺想的,都可以把文件中的內(nèi)容讀出來,并且是個(gè)字符串的形勢(shì)

  1. {fetch?file=”./aaaa.txt”?assign=”result”}
  2. {if?is_array($result)}
  3. <b>is?array</b>
  4. {else?if}
  5. <b>not?array</b>
  6. {/if}

 

 

]]>
http://www.86956464.com/blog/view-407.html/feed 481
htaccess實(shí)現(xiàn)域名綁定,拒絕其他域名訪問 http://www.86956464.com/blog/view-405.html http://www.86956464.com/blog/view-405.html#comments Mon, 17 Sep 2012 09:12:11 +0000 lin http://www.86956464.com/blog/?p=405 獨(dú)立ip的主機(jī),只要其他域名指向該ip都是可以訪問的,多域名訪問會(huì)產(chǎn)生大量重復(fù)內(nèi)容,對(duì)seo非常不利,我們可以利用htaccess實(shí)現(xiàn)域名綁定,拒絕其他域名訪問

在站點(diǎn)根目錄建立.htaccess文件,寫入如下內(nèi)容:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !www.86956464.com [NC]
RewriteCond %{HTTP_HOST} !zui88.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^.* – [F,L]

這樣實(shí)現(xiàn)的結(jié)果是只能通過www.86956464.com,zui88.com來訪問站點(diǎn),用其他的HOST訪問都會(huì)顯示403Forbidden。

其中:{HTTP_HOST}代表HTTP協(xié)議GET動(dòng)作同時(shí)傳遞的Host的值,[NC]代表忽略大小寫;[F]代表動(dòng)作為禁止;[L]代表最終匹配。

]]>
http://www.86956464.com/blog/view-405.html/feed 459
smarty 利用@ 在模版完整打印多維數(shù)組 http://www.86956464.com/blog/view-388.html http://www.86956464.com/blog/view-388.html#comments Sat, 21 Jul 2012 01:41:11 +0000 lin http://www.86956464.com/blog/?p=388 有時(shí)候我們希望直接在模版上打印數(shù)組變量以供調(diào)試,打印的方式可以用php自帶的print_r或者是自己寫的調(diào)試函數(shù),如debug().

如果直接這樣打印多維數(shù)組 {{$var|print_r}},在模版看到的結(jié)果會(huì)是遍歷后的所有的value,不會(huì)顯示完整的數(shù)組結(jié)構(gòu),正確的方法是在函數(shù)前加個(gè)@,意思是把變量作為整體去對(duì)待

{{$var|@print_r}}

]]>
http://www.86956464.com/blog/view-388.html/feed 613
php利用谷歌實(shí)現(xiàn)自動(dòng)在線翻譯 http://www.86956464.com/blog/view-386.html http://www.86956464.com/blog/view-386.html#comments Sat, 14 Jul 2012 07:41:19 +0000 lin http://www.86956464.com/blog/?p=386 php利用谷歌實(shí)現(xiàn)自動(dòng)翻譯,以下是兩種實(shí)現(xiàn)的方式,php文檔用utf8就不會(huì)出現(xiàn)亂碼問題

第一種利用curl:

function translate($text,$language='zh-cn|en'){
if(empty($text))return false;
@set_time_limit(0);
$html = "";
$ch=curl_init("http://google.com/translate_t?langpair=".urlencode($language)."&text=".urlencode($text));
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_HEADER, 0);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
$html=curl_exec($ch);
if(curl_errno($ch))$html = "";
curl_close($ch);
if(!empty($html)){
$x=explode("</span></span></div></div>",$html);
$x=explode("onmouseout=\"this.style.backgroundColor='#fff'\">",$x[0]);
return $x[1];
}else{
return false;
}
}
echo translate('去');
第二種:利用get方式
function googleTran($text){
if(empty($text)) return "";
//反間碟
$wf=@file_get_contents('http://translate.google.cn/translate_t?sl=zh-CN&tl=en&text='.$text.'#');
if (false===$wf||empty($wf)){
return false;
}

//截取相關(guān)信息
$return = "";

$star="style.backgroundColor='\#fff'\">";

$end="</span></span></div>";
$p = "#{$star}(.*){$end}#iU";//i表示忽略大小寫,U禁止貪婪匹配
if(preg_match_all($p,$wf,$rs))
{ print_r($rs);
return $rs[1][0];}

}

echo googleTran('去');

]]>
http://www.86956464.com/blog/view-386.html/feed 249
任丘市| 高平市| 顺昌县| 郯城县| 佛坪县| 舞钢市| 枣庄市| 阳原县| 乐山市| 庆安县| 罗甸县| 伊金霍洛旗| 日土县| 东阳市| 丹棱县| 阜新市| 石棉县| 若尔盖县| 出国| 曲阳县| 建平县| 萝北县| 安远县| 通山县| 项城市| 新蔡县| 邳州市| 西宁市| 峨眉山市| 鄱阳县| 绥芬河市| 云安县| 庆云县| 三都| 花垣县| 蛟河市| 新化县| 庆阳市| 莆田市| 雅安市| 南和县|