js+php实现静态页面实时调用用户登陆状态的方法
作者:shichen2014 时间:2023-10-09 22:32:45
本文实例讲述了js+php实现静态页面实时调用用户登陆状态的方法。分享给大家供大家参考。具体分析如下:
在程序开发中,经常会把页面做成html的静态形式,这样可以减轻服务器负载,但是也存在一个问题就是当注册用户登陆时,要在html页面显示登陆成功或需要登陆的提示,这样我们就必须想其它办法来实现了,下面我们就是利用js+php来实例的,当然还有ajax也可以实现,代码如下:
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<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输出形式才能正确被显示,代码如下:
<?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>');';
}
?>
希望本文所述对大家的php程序设计有所帮助。
标签:js,php,方法
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
使用Python完成SAP客户端的打开和系统登陆功能
2021-02-28 17:12:29
![](https://img.aspxhome.com/file/2023/2/93442_0s.png)
在 Python 中接管键盘中断信号的实现方法
2022-11-25 15:14:55
![](https://img.aspxhome.com/file/2023/5/118395_0s.jpg)
Python开发之pip安装及使用方法详解
2022-11-27 06:22:48
![](https://img.aspxhome.com/file/2023/6/90866_0s.png)
golang gorm的Callbacks事务回滚对象操作示例
2024-04-25 13:18:42
mysql 8.0.22 zip压缩包版(免安装)下载、安装配置步骤详解
2024-01-15 21:19:16
![](https://img.aspxhome.com/file/2023/7/97437_0s.jpg)
ES6正则表达式的一些新功能总结
2024-05-09 10:35:05
Python之ReportLab绘制条形码和二维码的实例
2023-06-26 09:43:30
![](https://img.aspxhome.com/file/2023/5/135005_0s.jpg)
由日文出错的Bug,重新认识 Replace 函数
2009-07-07 22:28:00
OpenCV2从摄像头获取帧并写入视频文件的方法
2022-04-10 07:15:22
python实现人人网登录示例分享
2022-06-25 09:17:51
Python利用turtle库绘制彩虹代码示例
2022-03-04 03:55:01
![](https://img.aspxhome.com/file/2023/3/72853_0s.png)
python实现自动获取IP并发送到邮箱
2023-02-15 13:09:56
Oracle分页查询的实例详解
2024-01-24 15:41:27
快速了解Python开发中的cookie及简单代码示例
2023-05-29 11:04:05
![](https://img.aspxhome.com/file/2023/7/128787_0s.png)
浅谈ACCESS数据库升迁SQLSERVER注意事项
2007-08-11 13:44:00
python中 logging的使用详解
2023-01-11 21:31:14
MySQL之Explain详解
2024-01-12 21:14:55
![](https://img.aspxhome.com/file/2023/2/121582_0s.png)
python缺失值填充方法示例代码
2023-06-28 12:23:24
![](https://img.aspxhome.com/file/2023/1/126931_0s.png)
详解Django中六个常用的自定义装饰器
2021-02-10 03:03:09
Python动态导入模块和反射机制详解
2023-07-16 14:02:10
![](https://img.aspxhome.com/file/2023/6/90286_0s.png)