sqlite+php+ajax 即時聊天系統(ajax 長串連)一

來源:互聯網
上載者:User

標籤:sqlite   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 class="main"><div class="panel panel-default">  <div class="panel-heading">登入</div>  <div class="panel-body"><form method="POST" action="">  <div class="form-group">    <label for="exampleInputEmail1">帳號</label>    <input type="text" name="username" class="form-control" id="exampleInputEmail1" placeholder="Enter email">  </div>  <div class="form-group">    <label for="exampleInputPassword1">密碼</label>    <input type="password" name="password" class="form-control" id="exampleInputPassword1" placeholder="Password">  </div>    <input type="submit" name="submit" class="btn btn-default" value="登入">  <a type="button" class="btn btn-default" href="/message/register.php">註冊</a></form>    </div></div></div><?php if($_POST['submit']){//登入,並且擷取sessioninclude '../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 長串連)一

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.