|
|
2#

楼主 |
发表于 2008-10-30 14:25:50
|
只看该作者

用PHP编程开发“虚拟域名”系统
我们需要在整个HTTP头信息中取出Host信息,然后将http://www.jj.jx.cn/www.xxx.xxx/default.htm形式的第一部分“www”,即HostName(也即是用户注册的name)单独取出,作为重定向检索的关键字。
检索到用户注册的URL信息后,我们给用户浏览器送一个重定向命令“Localtion: http://www.jj.jx.cn/somewhere/sample.html”,将用户重定向到指定页面。
在PHP3中,有函数GetAllHeader(),取得浏览器送出的HTTP头信息。我们主要需要使用此函数来完成整个程序。
后面附有源程序,由于只是实验性质的,所以在查询用户信息时,没有使用数据库,如果整个系统要实际应用的话,一定要和数据库挂接起来,不然查询用户信息的过程将是十分漫长,大大影响效率,而且用户数据的管理也不方便。
在源程序中,所有用户信息记录在data子目录下user.dat文件中。其格式为:
username:
http://octopus.cdit.edu.cn/~qap213/index.html
附PHP3源程序:
以下为引用的内容:
<?
//Get HTTP’s Header and parse it//
= getallheaders();
'www.knowsky.com
while (list(, ) = each()) {
if(=="Host"){= strtok(,".");}}
//Jump out the Banner's Window//
echo '<script language="JavaScript">',
'msg=window.open("banner.htm","sample",
"toolbar=no","directories=no",directories=no","menubar=no");’,
'</script>';
// seek the user information from the recorded file//
if(!=file("data/user.dat")){echo "Open Data File Error!!";}
="http://";
for(=0;<count();++)
if(strtok(,":")==){
=; }
if(=="http://"){echo "not found the uesrname of Data!";}
else{
echo '<meta http-equiv="refresh" content="0;','url=',,'">';} |
|