IE的Ajax缓存问题解决方法
IE对Ajax请求使用缓存,可以说有好有坏,但在用到即时数据请求时,就需要防止IE缓存Ajax,具体方法:
在AJAX请求页面后加个随机函数,比如使用随机时间函数。
在javascript发送的URL后加上qtime=Math.random(),例如:
URL+"&"+"qtime="+Math.random();
IE对Ajax请求使用缓存,可以说有好有坏,但在用到即时数据请求时,就需要防止IE缓存Ajax,具体方法:
在AJAX请求页面后加个随机函数,比如使用随机时间函数。
在javascript发送的URL后加上qtime=Math.random(),例如:
URL+"&"+"qtime="+Math.random();
php正则匹配中文的方法:
$str = "04aol汉字"; $pattern = "/^(\d{2})([A-Za-z]{3})([".chr(0xa1)."-".chr(0xff)."]+)$/"; if(preg_match($pattern, $str, $tmp)) { var_export($tmp); }
显示结果:
array ( 0 => '04aol汉字', 1 => '04', 2 => 'aol', 3 => '汉字', )
ignore_user_abort,这个函数可以帮助我们实现像linux中的cron一样实现计划任务,用户关掉浏览器后还可以执行。
使用方法:先使用函数set_time_limit(0)设置程序的执行时间为无限制。
例:
1 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 | <?php // Ignore user aborts and allow the script // to run forever ignore_user_abort(true); set_time_limit(0); echo 'Testing connection handling in PHP'; // Run a pointless loop that sometime // hopefully will make us click away from // page or click the "Stop" button. while(1) { // Did the connection fail? if(connection_status() != CONNECTION_NORMAL) { break; } // Sleep for 10 seconds sleep(10); } // If this is reached, then the 'break' // was triggered from inside the while loop // So here we can log, or perform any other tasks // we need without actually being dependent on the // browser. ?> |
最近需要整理一个整站的php代码规范视图,前几天发现phpCB整理视图非常好,但有个缺点是不能批量处理,使用过程中发现phpCB是一个CMD程序,马上就想到php的system函数调用cmd,想到就做,下面是phpCB批量转换的php程序:
继续阅读…
用phpCodeBeautifier工具可以帮你格式化代码视图,规范代码缩进习惯,很实用的一个工具。
用法:DOS窗口打开phpCodeBeautifier工具目录,语法格式为:
phpCB.exe [options] [filename]
有些常用的配置变量写入MYSQL比较麻烦,可以写入一个php配置文件,在需要的地方引入这个配置文件即可。写入方法如下(摘入):
$configfile = @file_get_contents('./config.inc.php'); $configfile = trim($configfile); $configfile = preg_replace("/[$]dbhost\s*\=\s*[\"'].*?[\"'];/is", "\$dbhost = '$dbhost';", $configfile); $configfile = preg_replace("/[$]dbuser\s*\=\s*[\"'].*?[\"'];/is", "\$dbuser = '$dbuser';", $configfile); $configfile = preg_replace("/[$]dbpw\s*\=\s*[\"'].*?[\"'];/is", "\$dbpw = '$dbpw';", $configfile); $configfile = preg_replace("/[$]dbname\s*\=\s*[\"'].*?[\"'];/is", "\$dbname = '$dbname';", $configfile); $configfile = preg_replace("/[$]adminemail\s*\=\s*[\"'].*?[\"'];/is", "\$adminemail = '$adminemail';", $configfile); $configfile = preg_replace("/[$]tablepre\s*\=\s*[\"'].*?[\"'];/is", "\$tablepre = '$tablepre';", $configfile); $configfile = preg_replace("/[$]cookiepre\s*\=\s*[\"'].*?[\"'];/is", "\$cookiepre = '".random(3)."_';", $configfile); @file_put_contents('./config.inc.php', $configfile);
discuzs是一款不错的php开源社区软件,很多优秀的代码可以拿来借鉴。下面是从common.inc.php中提取出来的获取客户端IP的代码。
if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) { $onlineip = getenv('HTTP_CLIENT_IP'); } elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) { $onlineip = getenv('HTTP_X_FORWARDED_FOR'); } elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) { $onlineip = getenv('REMOTE_ADDR'); } elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) { $onlineip = $_SERVER['REMOTE_ADDR']; }
<?php $filename = "下载文件名"; $filesize = filesize('文件地址'); //获得文件大小 header('Pragma: public'); header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT'); header('Cache-Control: no-store, no-cache, must-revalidate'); header('Cache-Control: pre-check=0, post-check=0, max-age=0'); header('Content-Transfer-Encoding: binary'); header('Content-Encoding: none'); header('Content-type: application/force-download'); header('Content-Disposition: attachment; filename="'.$filename.'"'); header('Content-length: '.$filesize); ?>
这样在弹出文件下载框时,显示的文件名在不同的浏览器下面是不一样的。有的是乱码,有的是空白。
所以文件名统一使用utf-8编码,然后针对ie浏览器进行一次rawurlencode编码。
把以下代码放在header之前
if (preg_match(’/MSIE/’,$_SERVER['HTTP_USER_AGENT'])) { $filename = rawurlencode($filename); }
9月10日,腾讯邮箱已对外开放“域名邮箱”功能的体验,用户可将自己的域名作为邮箱后缀,免费开通属于自己的邮局,设置独一无二的个性邮箱。
据了解,域名邮箱是腾讯公司推出的一项个性化邮件服务。如果您拥有域名,只需要通过简单的设置,就能够创建以您域名作为邮箱后缀的邮箱。自定义喜欢的帐户名和邮箱的标志图案,您创建的域名邮箱帐户名可以随意指定了,不用担心喜欢的用户名被抢注的问题。用户只需访问domain.mail.qq.com就可以马上创建域名邮箱,用户也可以在登录qq邮箱后,在“设置”中的“体验室”找到域名邮箱服务的入口。