第一次登陆的时候去数据库验证一下,如果用户名密码正确,你就写一个Cookie到计算机里面,如果用户再登入就试图从Cookie里面把用户名密码取出来与数据库进行比对,如果正确,则直接让登入,这样就可以了,那么在用户那里,只会看到是自动登陆的。

解决方案 »

  1.   

    建议用cookie ,第一次登陆把用户名 密码 写到里边,下次在登陆先检测一下cookie是否存在这个用户
      

  2.   

    请问该怎么写呢 ?我是初学者,对php不熟,能给一段源码吗?我要改的是一套邮件系统的代码和一个聊天工具,我想将两个东西发到同一个网页,当在邮件的登录界面中输入用户名和密码之后,让系统记录用户名和密码,同时让一个聊天软件的web页也同时登录,(用户名和密码全都相同),但他们是两个不同软件的
     
    邮件系统的登录页代码如下:
    <?php
    require_once('lib/htmlHeader.inc'); 
    require_once('../kmslibs/KmsSessionMgr.inc'); 
    require_once('login.inc'); 
    header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); 
    header("Expires: Thu, 19 Nov 1981 08:52:00 GMT"); 
    header("Pragma: no-cache"); 
    $sx = & new sy(); 
    $l = $sx->tm(true); 
    if (!is_null($l)) { 
    $tn = ($l->getWebComponent() == KMS_WEBCOMPONENTWEBMAIL ? '/default/index.php' : '/express/index.php'); 
    header('Location: ' . $tn); 
    exit; 

    if (!$bk) $bk = "<kerio:text id='login-enter'/>"; 
    $ace = explode(",", $_SERVER["HTTP_ACCEPT_LANGUAGE"]); 
    $ti = strtolower(substr(trim($ace[0]), 0, 2)); 
    if (!$ti) $ti = "en"; 
    header("Content-Type: text/html; charset=utf-8"); 
    header("Content-Language: $ti"); 
    header("X-Kerio-Filter: translate=$ti"); 
    $alt = new cx('', array('login.css')); 
    $alt->dsr(SERVER_SOFTWARE . ' WebMail'); 
    $alt->alv(array(DOCTYPE, TITLE, FAVICON, CSSFILES)); 
    $epg = epg(); 
    $epp = false; 
    require_once('browser.inc'); 
    $bl = new bm(); 
    $cgi = $bl->bo() . $bl->aop(); 
    switch ($cgi) { 
    case 'msie7': 
    $epp = $cgi; 
    $epq = 336; 
    break; 
    case 'firefox20': 
    $epp = $cgi; 
    $epq = 234; 
    break; 

    ?>
    <meta name="viewport" content="width = 320" />
    <script type="text/javascript">
    <!--
    function epr() {
    document.ach.kerio_username.focus();
    <?php if ($epg): ?>
    if (document.getElementById && document.createElement && encodeURIComponent) {
    if (top.location != document.location) top.location = document.location;
    document.getElementById('modeSelection').innerHTML = ''
    + '<table>'
    + '<tr><td colspan="2" class="small"><kerio:text id='login-mode'/></td></tr>'
    + '<tr>'
    + '<td valign="top"><input name="kerio_mode" id="m0" type="radio" value="full" checked></td>'
    + '<td><label for="m0"><kerio:text id='login-mode-full'/></label></td>'
    + '</tr>'
    + '<tr>'
    + '<td valign="top"><input name="kerio_mode" id="m1" type="radio" value="mini"></td>'
    + '<td><label for="m1"><kerio:text id='login-mode-express'/></label></td>'
    + '</tr>'
    + '</table>';
    document.getElementById('logoText').innerHTML = 'WebMail';   
    <?php if ($_GET['mode'] == 'mini' || $_GET['mode'] == 'pda'): ?>   
    document.forms[0].kerio_mode[1].checked = true;   
    <?php endif ?>
    <?php if ($epp !== false): ?>
    document.getElementById('hint').innerHTML = ''
    + '<a href="hints.php?showHint=<?php print $cgi ?>&lang=<?php print $ti ?>" target="hints" '
    + 'onclick="window.open(\'hints.php?showHint=<?php print $cgi ?>&lang=<?php print $ti ?>\', \'hints\', '
    + '\'width=380,height=<?php print $epq ?>,top=50,left=50,resizable=yes,scrollbars=yes\');'
    + 'return false;"><kerio:text id='hint-recommended-settings'/></a>';
    <?php endif ?>
    }
    <?php endif ?>
    }
    -->
    </script>
    </head>
    <body onload="epr()">
    <div id='upSpacer'></div>
    <form name="ach" action="dologin.php" method="post" style="margin:0">
    <input name="bop" type="hidden" value="internal">
    <div class='contentDiv'>
    <table class="mainTable" align="center">
    <tr><td colspan="2">
    <div class='logoDiv'></div>
    <div id="logoText" class="caption">WebMail Mini</div><br></td></tr>
    <?php
    if (!is_null($_GET['reason'])) { 
    switch ($_GET['reason']) { 
    case "failure": 
    $act = "<kerio:text id='login-err-failure'/>"; 
    break; 
    case "expired": 
    $act = "<kerio:text id='login-err-expired'/>"; 
    break; 
    case "logout": 
    $act = "<kerio:text id='login-err-logout'/>"; 
    break; 
    default: 
    $act = ""; 
    break; 


    if (strlen($act) > 0) { 
    echo "<tr><td colspan=\"2\"><span class=\"error\">" . $act . "<br><br></span></td></tr>"; 

    ?>
    <tr><td colspan="2">
    <?php echo $bk; ?><br>&nbsp;
    </td></tr>
    <tr><td nowrap><span class="caption"><kerio:text id='login-username'/></span></td><td>
    <input name="kerio_username" class="input_text" type="text" size="15">
    <?php if ($_GET['mode'] == "pda"):?>
    <input name="dui" type="hidden" value="yes">
    <?php endif;?>
    </td></tr>
    <tr><td nowrap><span class="caption"><kerio:text id='login-password'/></span></td><td>
    <input name="kerio_password" type="password" size="15" class="input_text"></td></tr>
    <tr>
    <td colspan="2"><div id="modeSelection"></div></td>
    </tr>
    <tr>
    <td>&nbsp;</td><td><input type="submit" class="input_button" value="<kerio:text id='login-submit'/>"></td>
    </tr>
    </table>
    </form>
    </div>
    <?php if ($epp): ?>
    <div id="hint"></div>
    <?php endif ?>
    </body>
    </html>
      

  3.   

    聊天软件的代码如下:<html lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>SparkWeb</title>
    <script src="AC_OETags.js" type="text/javascript"></script>
    <style>
    body { margin: 0px; overflow:hidden }
    </style>
    <script type="text/javascript"> 
        var mw_flashMovieId = "SparkWeb"; // the id/name of your flash app's HTML DOM element     
        var mw_flashContainerId = "container"; // the id/name of the flash element's surrounding div element  
    </script>
    <script type="text/javascript">
    <!--
    // -----------------------------------------------------------------------------
    // Globals
    // Major version of Flash required
    var requiredMajorVersion = 9;
    // Minor version of Flash required
    var requiredMinorVersion = 0;
    // Minor version of Flash required
    var requiredRevision = 0;
    // -----------------------------------------------------------------------------
    // -->
    </script>
    </head><script type="text/javascript">
    function jive_sparkweb_getConfig()
    {
    return {
    server: "igniterealtime.org",
    connectionType: "socket",
    port: "5222",
    autoLogin: "false"
    };
    }
    </script>
    <script type="text/javascript">
        // Copyright 2007 www.flexcapacitor.com, www.drumbeatinsight.com 
        // Version 1.0.0
        
        // global array of html elements
        htmlControls = new Array();
        
        var timer;
        var titleStr;
        var nicknameStr;
        var bodyStr;
        var flashPlayer;
        
        
    // add HTML element to the page
        function addChild(o) {
         if (o.type=="division") {
         addChildDivision(o);
         }
         else if (o.type=="iframe") {
         addChildIFrame(o);
         }
        }
        
        function detectFlashPlayer(){
        try {
         if(navigator.appName.indexOf("Microsoft") != -1){
         flashPlayer = window.SparkWeb;
         }
         else {
         flashPlayer = window.document.SparkWeb;
         }
        }
         catch(e){
         alert(e);
         }
        }
        
        window.onblur = function() {
         if(flashPlayer != null && flashPlayer.setFocused){
    flashPlayer.setFocused(false);    
    }
    };

    window.onfocus = function() {
    if(flashPlayer != null && flashPlayer.setFocused){
    flashPlayer.setFocused(true);
    }
    };


    function isReady(){
    return true;
    }

        
        // add iframe to the page
        function addChildIFrame(o) {
        
         if (getElement(o.id)) {  
    // do nothing for now
         }
        
    var newElement = document.createElement("iframe");
    newElement.id = o.id;
    newElement.name = o.name;
    newElement.movieId = o.movieId;
    newElement.width = o.width;
    newElement.height = o.height;
    newElement.frameBorder = o.frameborder;
    newElement.style.position = o.position;
    setSize(newElement,o.width,o.height);
    moveElementTo(newElement,o.x,o.y);
    //newElement.style.backgroundColor = "transparent";
    // always 0px - do not add a border to the iframe itself
    // add a child div and add a border to that or add border in mxml
    newElement.style.border = o.border;
    newElement.src = o.source;

    //  use innerHTML or DOM element creation methods to put content into body
    document.body.appendChild(newElement);

    newElement.onload = new function() {
    // set a flag so the application knows the page is loaded
    // looking for a reliable method that works cross browser
    }
        }
        
        // add division to the page
        function addChildDivision(o) {
    var newElement = document.createElement("div");
    newElement.id = o.id;
    newElement.name = o.name;
    newElement.movieId = o.movieId;

    newElement.style.position = o.position;
    setSize(newElement,o.width,o.height);
    moveElementTo(newElement,o.x,o.y);
    newElement.style.backgroundColor = "#" + o.backgroundColor;
    newElement.style.padding = "0px";
    newElement.style.margin = "0px";
    // always 0px - do not add a border to the container div tag
    // add a border in mxml or add a child div tag in the htmlText property and add a border to that
    newElement.style.border = o.border;
    newElement.innerHTML = o.htmlText;

    document.body.appendChild(newElement);
    setScrollPolicyById(o.id, o.htmlScrollPolicy);

    addToGlobalArray(newElement, o.type);
        }
        
    // add to associative array
    function addToGlobalArray(el, elementType) {
    var newElement = new Object();
    newElement.element = el;
    newElement.id = el.id;
    newElement.loaded = false;
    newElement.type = elementType;
    htmlControls[el.id] = newElement;
    }
        
    // gets the element by name
    function getElement(id) {
    if (htmlControls[id]) {
    return htmlControls[id].element;
    }
    return document.getElementById(id);
    }

    function appendMessage(id, message){
    try {
    var f = getElement(id);
    var p = f.contentWindow.document;
           window[id].appendMessage(message);
    }
    catch(err){
    setTimeout('appendMessage("+id+", "+message+")', 3000);
    }
    }

    function isReady(id){
    try {
    var f = getElement(id);
    var p = f.contentWindow.document;
           return window[id].isReady();
    }
    catch(err){
    }
    return false;
    }

    function changeTitle(title){
    window.document.title = title;
    clearTimeout(timer);
    }

    function alertTitle(title, username){
    clearTimeout(timer);
    window.document.title = title;
    titleStr = title;
    nicknameStr = username;
    timer = setTimeout("showNickname()", 1000);
    }

    function showNickname(){
    window.document.title = nicknameStr;
    timer = setTimeout("showTitle()", 1000);
    }

    function showTitle(){
    window.document.title = titleStr;
    timer = setTimeout("showNickname()", 1000);
    }


    function showBody(){
    window.document.title = bodyStr;
    timer = setTimeout("showTitle()", 1000);
    }

    function refreshPage(){
    window.location.reload( false );
    }



    // cannot get height of pages loaded from different domains
    // ie, page is hosted at www.yoursite.com and you load www.google.com will fail with return value of -1
    // works in ff and ie. not tested in mac browsers - 
    function getElementHeight(id){
    var el = getElement(id);
    moz = (document.getElementById && !document.all);

    if (el){

    // check the height value
    try {

    /*** return div height ***/
    if (el.nodeName.toLowerCase()=="div") {
    var scrollHeight = el.scrollHeight;
    var divHeight = el.style.height;
    divHeight = (scrollHeight > parseInt(divHeight)) ? scrollHeight : divHeight;
    return divHeight;
    }

    /*** return iframe height ***/
    //moz
    if (moz) {
    return el.contentDocument.body.scrollHeight;
    }
    else if (el.Document) {
    return el.Document.body.scrollHeight;
      

  4.   

    }
    }
    catch(e)
    {
    //An error is raised if the IFrame domain != its container's domain
    //alert('Error: ' + e.number + '; ' + e.description+'\nPossibly - Cannot access because page domain does not equal container domain');
    return -1;
    }
    }
    } // get property value
    function getElementValue(id, elProperty){

    // if periods are in the name assume absolute path 
    // otherwise assume element id
    if (id.indexOf('.')!=-1) {
    var newArr = id.split('.');
    var elValue = "";

    try {
    el = window;
    for (var i=0;i < newArr.length;i++) {
    el = el[newArr[i]];
    }
    return el;
    }
    catch (e) {
    //alert("Whoooops!! Cant find " + elId);
    // should return null or undefined here
    return -1;
    }
    }
    else {
    // try and get property value
    try {
    var el = getElement(id);
    var elValue = el[elProperty];
    return elValue;
    }
    catch(e) {
    //alert("Error: Can't find " + elId + "." + elProperty);
    // should return null or undefined here
    return -1;
    }
    }
    }

    // get HTML content
    function getHTML(id, elementType) {
    var el = getElement(id);
    if (el!=null) {

    if (elementType =="division") {
    return el.innerHTML;
    }
    }
    return "";
    } // get reference to the flash movie
    function getMovieById(id) {
    if (navigator.appName.indexOf ("Microsoft") !=-1) {
    return window[id];
    } else {
    return window.document[id];
    }
    }

    // hide element by name
    // set height of content to 0px so the 
    // flash context menu appears in the right location
    function hide(id, hideOffscreen, offscreenOffset) {
    var el = getElement(id);
    if (hideOffscreen) {
    el.style.width = "0px";
    el.style.height = "0px";
    }
    el.style.visibility = "hidden";
    }

    // move element to new location
    function moveElementTo(el,x,y) {
    el.style.left = parseInt(x) + "px";
    el.style.top = parseInt(y) + "px";
    }

    // forces redraw
    function refresh(id) {
    var el = getElement(id);
    el.style.cssText = el.style.cssText;
    }

    function removeEle(id){
    var olddiv = getElement(id);
       document.body.removeChild(olddiv);  
    }

    // remove
    function remove(id) {
    hide(id, true);
    var el = getElement(id);
    //el = undefined; // not sure how to delete
    }
        
    // set document title
        function setDocumentTitle(title) {
            window.document.title = title;
            return 1;
        }

    // set HTML content
    function setHTML(id, htmlText, elementType) {
    var el = getElement(id);
    if (el!=null) {

    if (elementType =="division") {
    el.innerHTML = htmlText;
    }
    }
    }

    // set position
    function setPosition(id,x,y) {
    var el = getElement(id); // LEFT
    if (x != undefined) {
    el.style.left = x + "px";
    }
    // TOP
    if (y != undefined) {
    //alert(y)
    el.style.top = y + "px";
    }
    }

    // set scroll policy of element
    function setScrollPolicy(el, overflow) {
    if (overflow != "resize") {
    el.style.overflow = overflow;
      

  5.   

    COOKIE 可以的,从客户端取COOKIE内容,判断两个WEB对登陆状态的判定条件一致就可以了