好吧,我下载了这个脚本http://frug.github.io/AJAX-Chat/的独立版本,发现它没有添加新用户的注册页面。所以我决定自己编写。 用户信息存储在chat \ lib \ data \ users.php中:
<?php
/*
* @package AJAX_Chat
* @author Sebastian Tschan
* @copyright (c) Sebastian Tschan
* @license Modified MIT License
* @link https://blueimp.net/ajax/
*/
// List containing the registered chat users:
$users = array();
// Default guest user (don't delete this one):
$users[0] = array();
$users[0]['userRole'] = AJAX_CHAT_GUEST;
$users[0]['userName'] = null;
$users[0]['password'] = null;
$users[0]['channels'] = array(0);
// Sample admin user:
$users[1] = array();
$users[1]['userRole'] = AJAX_CHAT_ADMIN;
$users[1]['userName'] = 'jafar';
$users[1]['password'] = '123456';
$users[1]['channels'] = array(0,1);
// Sample moderator user:
//$users[2] = array();
//$users[2]['userRole'] = AJAX_CHAT_MODERATOR;
//$users[2]['userName'] = 'moderator';
//$users[2]['password'] = 'moderator';
//$users[2]['channels'] = array(0,1);
// Sample registered user:
$users[3] = array();
$users[3]['userRole'] = AJAX_CHAT_USER;
$users[3]['userName'] = '123';
$users[3]['password'] = '123';
$users[3]['channels'] = array(0,1)
?>
我在该文件夹中添加了id.txt文件以保存最后一个用户ID,然后我为注册页面编写了这段代码:
<html>
<body>
<?php
if(isset($_GET['name']) && isset($_GET['password']))
{
$name = $_GET['name'];
$pass = $_GET['password'];
$users = file_get_contents('.\lib\data\users.php');
$id = file_get_contents('.\lib\data\id.txt');
$users = substr($users,0,strlen($users)-3);
$users = $users . '$users['. $id .'] = array();
$users[' . $id . '][\'userRole\'] = AJAX_CHAT_USER;
$users[' . $id . '][\'userName\'] = \'' . $name . '\';
$users[' . $id . '][\'password\'] = \'' . $pass . '\';
$users[' . $id . '][\'channels\'] = array(0,1); ' ;
$id=$id+1;
$id=$id+'';
$a = file_put_contents('.\lib\data\users.php',$users.'?>');
$a = $a +file_put_contents('.\lib\data\id.txt',$id);
//if($a!=2)
//echo 'Error !';
}
?>
<center>
<form method=get>
username <input type=text name=name >
<br>
password <input type=password name=password >
<input type=submit>
</form>
</center>
但是当我试图打开chatroom agian时,我收到了这个错误:
XML Parsing Error: no element found Location: http://localhost/irc/chat/ Line Number 1, Column
1:^
我做错了什么?
答案 0 :(得分:0)
您正在投入 标签内 PHP代码必须位于顶部。希望对您有帮助
答案 1 :(得分:-1)
我不知道是否会破坏任何内容,但您没有关闭<html>
代码或<body>
代码。您也没有关闭任何输入标签,因此您在输入内部有输入。尝试关闭html和body标记,对于输入标记,您可以将>
替换为/>
。如果它仍然无法工作,我会进一步研究。