网站管理脚本实用指南
1. 随机文本显示
1.1 功能概述
服务器端内置的包含功能为扩展网站提供了很多出色的方法。其中一个受众多网站管理员喜爱的功能是,让网页的某个元素在每次页面加载时都发生变化。这个不断变化的元素可以是图形、新闻片段、特色子页面,或者只是网站的标语,每次访问时稍有不同,以保持读者的兴趣,并希望他们再次访问。
1.2 代码实现
#!/bin/sh
# randomquote - Given a one-line-per-entry datafile, this
# script randomly picks one line and displays it. Best used
# as an SSI call within a web page.
awkscript="/tmp/randomquote.awk.$$"
if [ $# -ne 1 ] ; then
echo "Usage: randomquote datafilename" >&2
exit 1
elif [ ! -r "$1" ] ; then
echo "Error: quote file $1 is missing or not readable" >&2
exit 1
fi
trap "/bin/rm -f $awkscript" 0
cat << "EOF" > $awkscript
BEGIN { srand() }
{ s[NR] = $0 }
END { print s[randint(NR)] }
function
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



