在程序开发中,经常会把页面做成html的静态形式,这样可以减轻服务器负载,但是也存在一个问题就是当注册用户登陆时,要在html页面显示登陆成功或需要登陆的提示,这样我们就必须想其它办法来实现了,下面我们就是利用js+php来实例的,当然还有ajax也可以实现,代码如下:
1 2 3 4 5 6 7 8 9 10 11 | <!doctype html>
<html xmlns= "http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv= "content-type" content= "text/html; charset=gb2312" />
<title>静态页面实时调用用户登陆与退出登陆程序(网页特效调用php代码)</title>
</head>
<body>
<script language= "javascript" src= "/loginajax.php?fid={fid}" ></script>
</body>
</html>
|
登录后复制
loginajax.php文件,因为loginajax.php是由js形式调用输出,所以在这个文件里面的代码由于按js输出形式才能正确被显示,代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 | <?php
$id = isset( $_get ['fid'] )? $_get ['fid']:0;
if ( !isset( $_cookie ['vvg']) ){
?>
document.write('用户名:<input type= "text" class = "pl_sty1" name= "username" id= "username" />');
document.write('<input name= "action" type= "hidden" value= "login" />');
<?php
}
else
{
echo 'document.write('['. $_cookie ['realname'],']发言 <a href=/login/login.php?action=logout>退出</a>');';
}
?>
|
登录后复制
本文地址:
转载随意,但请附上文章地址:-)