Archive for August, 2008

js检测firefox3是否读取了缓存页面

firefox 3 浏览器会忽略

等标签。详情请参看 https://bugzilla.mozilla.org/show_bug.cgi?id=327790#c8.
这样在某些情况下即使用户使用强制刷新页面,firefox仍然会去读取他的高速缓存,而根本没去请求服务器。
在ecmall后台使用的一个解决方法是:在页面onload事件中,用js去检测当前页面是否是缓存页面,如果是,则在但前页面url后面加上一个时间戳后,在reload一下,就能获取到最新的页面。
检测原理如下:
服务器每次请求都把请求时间写入cookie,要防止缓存的页面把页面修改时间也该改当前请求时间。页面onload事件中用js检查是否两个事件是否一致,如果页面修改时间小于cookie中时间,说明该页面是从高速缓存中读取的。
php中设置cooke请求时间代码:

set_cooke(‘lastModified’, gmdate(‘D, d M Y H:i:s’));

php设置稳定修改时间代码:

header(‘Last-Modified: ‘. gmdate(‘D, d M Y H:i:s’) . ‘ GMT’); //last modified

js检测代码

//只有firefox 3 才检查
if (navigator.userAgent.toLowerCase().indexOf(“firefox/3″) != – 1){
$doc_last_date = new Date(document.lastModified);
//document.getCookie 是emall获取cooke的一个函数,具体代码会js都应该知道吧
$cookie_last_date = new Date(document.getCookie(‘lastModified’).replace(/\+/g, ‘ [...]

php 使用msmtp发送邮件

网站通过内置服务器发给用户的邮件,经常被用户客户端默认为垃圾邮件。
这是一个很头痛的问题。我曾经试过设置各种各样的邮件头部,都没能逃脱这个厄运。现在可行的方法是通过php直接访问一些专门smtp服务器把邮件发送出去。gmail就是一个不错的选择,还支持自定义域名。
msmtp是一个命令行的smtp客户端,在php.ini 设置:
sendmail_path = “/opt/local/bin/msmtp –file=/xxx/.msmtprc -t”
即可通过php mail()函数来发送邮件,这个比直接用php来访问smtp好得多。

ps:
msmtp 安装设置可参考 这里
gmail 发送邮件人数不能超过100.原文如下:
“You can send a single message to a maximum of 500 recipients through the web interface, or up to 100 recipients when using POP access. Their email addresses can be distributed among the To, Cc, and Bcc fields.”

php mail 测试代码:

msmtp 安装手记

msmtp是一个命令行的smtp客户端。可是php等脚本调用。
使用默认邮件服务器发送邮件容易被当作垃圾邮件,如果执行使用php进行smtp邮件发送效率太低。msmtp可以作为中介,在google申请一个企业邮箱专门用于网站发邮件,还不用担心邮件被用户当垃圾邮件。
本安装方法在Mac OS leopard操作系统下测试成功。
1.安装MacPort
请到http://www.macports.org下载最新MacPort安装包。

macport会默认安装到/opt/local/bin目录下。
2.打开一个shell窗口:

执行echo $SHELL。
如果bash shell 则执行
echo “export PATH=$PATH:/opt/local/bin” >> ~/.profile
重新开启bash shell使设置变量生效。
3. 执行 sudo port intall msmtp
msmtp安装完成后,执行 touch ~/.msmtprc
以下为.msmtprc的模板:
#Set default values for all following accounts
defaults
tls on
tls_trust_file ~/msmtp/ca-certificates.crt
logfile ~/msmtp/msmtplog
# Gmail service
account gmail
host smtp.gmail.com
from xxx@gmail.com
auth on
user xxxx
password xxxxxx
#port 587                 #可要可不要的
# A freemail service
#account freemail
#host smtp.freemail.example
#from joe_smith@freemail.example
#auth on
#user joe.smith
#password secret
# A second mail address at the same freemail service
#account [...]