Home > php教程 > php手册 > 静态页面实时调用用户登陆与退出登陆程序,js调用php代码

静态页面实时调用用户登陆与退出登陆程序,js调用php代码

WBOY
Release: 2016-05-25 16:38:51
Original
1055 people have browsed it

在程序开发中,经常会把页面做成html的静态形式,这样可以减轻服务器负载,但是也存在一个问题就是当注册用户登陆时,要在html页面显示登陆成功或需要登陆的提示,这样我们就必须想其它办法来实现了,下面我们就是利用js+php来实例的,当然还有ajax也可以实现,代码如下:

<!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>
Copy after login

loginajax.php文件,因为loginajax.php是由js形式调用输出,所以在这个文件里面的代码由于按js输出形式才能正确被显示,代码如下:

<?php 
 $id = isset( $_get[&#39;fid&#39;] )?$_get[&#39;fid&#39;]:0;  
 if( !isset($_cookie[&#39;vvg&#39;]) ){ 
?>
document.write(&#39;用户名:<input type="text" class="pl_sty1" name="username" id="username" />&#39;); 
document.write(&#39;<input name="action" type="hidden" value="login" />&#39;); 
<?php
} 
 else 
 { 
  echo &#39;document.write(&#39;[&#39;.$_cookie[&#39;realname&#39;],&#39;]发言 <a href=/login/login.php?action=logout>退出</a>&#39;);&#39;; 
} 
?>
Copy after login


本文地址:

转载随意,但请附上文章地址:-)

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template