sqlite+php+ajax 即时聊天系统(ajax 长连接)一

sqlite+php+ajax 即时聊天系统(ajax 长连接)一,第1张

概述说点废话:今天lol的时候 碰到一个坑货,技术确实不错,到后面,被我说了一句,那家伙居然说让我求他,他就玩。我骂了他一句傻逼。我就挂机,看着他们输了。有时候,看到别人要坑,我就先下手为强! 思路:sqlite:数据库数据,用来保存聊天记录;php链接数据库,接受ajax传送数据,返回处理结果;ajax异步获取聊天数据,异步更新聊天记录; 所用的数据库类,请参照前面blog。 一.登录 <?php

说点废话:今天lol的时候 碰到一个坑货,技术确实不错,到后面,被我说了一句,那家伙居然说让我求他,他就玩。我骂了他一句傻逼。我就挂机,看着他们输了。有时候,看到别人要坑,我就先下手为强!


思路:sqlite:数据库数据,用来保存聊天记录;PHP链接数据库,接受AJAX传送数据,返回处理结果;AJAX异步获取聊天数据,异步更新聊天记录;

所用的数据库类,请参照前面blog。



一.登录

<?PHP session_start(); ?><!DOCTYPE HTML><HTML lang="zh-cn"><head><Meta charset='utf-8'><link href="http://cdn.bootCSS.com/bootstrap/3.3.2/CSS/bootstrap.min.CSS" rel="stylesheet"><!-- HTML5 shim and Respond.Js for ie8 support of HTML5 elements and media querIEs --><!--[if lt IE 9]>  <script src="http://cdn.bootCSS.com/HTML5shiv/3.7.2/HTML5shiv.min.Js"></script>  <script src="http://cdn.bootCSS.com/respond.Js/1.4.2/respond.min.Js"></script><![endif]--></head><style>	.main{		wIDth: 500px;		margin: 50px auto;	}	.info-List{		border: 1px solID #dedede; 		height: 200px;		overflow-y: scroll;	}	.info-List li{		border: 0px;	}</style><body onload="cycle();"><script>var xmlhttp;var a;//生成xmlhttp对象function create(){	if(window.XMLhttpRequest)	{		xmlhttp=new XMLhttpRequest();	}else{		xmlhttp=new ActiveXObject("Microsoft.XMLhttp");	}}//回调方法function callback(){	if(xmlhttp.readyState==4&&xmlhttp.status==200)	{		document.getElementByID("info_List").INNERHTML=xmlhttp.responseText;//获取PHP获取到的聊天记录	}}//启动function run(){	create();	xmlhttp.open("GET","/message/first.PHP",true);	xmlhttp.onreadystatechange=callback;	xmlhttp.send();	}每隔500毫秒,便更新一次表中数据。function cycle(){	setInterval("run()",500);}</script><div >	<div >	  <div >登录</div>	  <div >		<form method="POST" action="">		  <div >		    <label for="exampleinputEmail1">账号</label>		    <input type="text" name="username"  ID="exampleinputEmail1" placeholder="Enter email">		  </div>		  <div >		    <label for="exampleinputPassword1">密码</label>		    <input type="password" name="password"  ID="exampleinputPassword1" placeholder="Password">		  </div>		  		  <input type="submit" name="submit"  value="登录">		  <a type="button"  href="/message/register.PHP">注册</a>		</form>	  		  </div>	</div></div><?PHP if($_POST['submit']){//登录,并且获取session	include '../sqlite/sqlite_db.PHP';	$db=new sqliteDb();	$res=$db->query('user',' where username="'.$_POST['username'].'" and password="'.$_POST['password'].'"');	if ($res) {		foreach ($res as $key => $row) {			$_SESSION['user']['username']=$row['username'];			$_SESSION['user']['nickname']=$row['nickname'];		}				echo '<script>window.location.href="/message/";</script>';	}}?>
 
 
<script src="my.Js"></script><script src="http://cdn.bootCSS.com/jquery/1.11.2/jquery.min.Js"></script><script src="http://cdn.bootCSS.com/bootstrap/3.3.2/Js/bootstrap.min.Js"></script></body></HTML>
总结

以上是内存溢出为你收集整理的sqlite+php+ajax 即时聊天系统(ajax 长连接)一全部内容,希望文章能够帮你解决sqlite+php+ajax 即时聊天系统(ajax 长连接)一所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1179708.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存