在login.php里连接数据库,判断用户名是否正确,正确的话,就跳转到 index.php,不正确就返回 PHP code
if(正确)
{
$_SESSION['checked']=...;
echo("<script language='javascript'>location.href='index.php';</script>");
}
else
{
echo("<script language='javascript'>alert('用户名或密码错误');history.go(-1);</script>");
}
[/code]

解决方案 »

  1.   


    if(正确) 

    $_SESSION['checked']=...; 
    echo(" <script language='javascript'>location.href='index.php'; </script>"); 

    else 

    echo(" <script language='javascript'>alert('用户名或密码错误');history.go(-1); </script>"); 
      

  2.   


    对用户名、密码等的判断是在什么地方?是在form里还是用$_GET()来逐个判断?
      

  3.   

    在本页面处理就可以<form action=<?php $PHP_SELF;?> method='post' >
      

  4.   

    1 客户端,服务器端都要判断。
    2 对于需要查询数据库才能给出的答案,最好使用ajax异步返回数据来提示用户。
      

  5.   

    或在form中加个标记<?phpif ($_GET("action")=="submit")
    {
      //..处理
    }
    ?><form action='?action=submit' method="post"  >
      

  6.   

    对于用户名,你可以通过ajax在form里进行判断,对于密码最好是在你的处理登录面页的文件中处理,form提交方式最好用post,密码用get方法提交不安全!
      

  7.   


    可以给个AJAX的例子看看吗?对AJAX不了解
      

  8.   

    <? require("inc/config.php") ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    <body>
    <?php
    if($_POST)
    {
    $name=$_POST['username'];
    /*判断数据链接是否存在?*/
    if(!$conn)
    echo "数据库链接失败:)<br>";
    else
    echo "数据库链接成功<br>";
    /*判断数据链接是否存在?*/
    mysql_select_db("php");#选择数据库很重要必须指定相应的数据库
    $result=mysql_query("select name from username where name='".$name."'",$conn);#查询数据库中username的内容
    if(!($name=mysql_fetch_object($result)))
    {
    echo "非法用户";
    }
    else
    {
    echo"合法用户!";
    }
    }
    ?>
    <form id="form" name="form" method="post" action="index.php">
    <div>您的名字:
        <input name="username" type="text" id="username" size="10" maxlength="10" />
    </div>
    <div>
    <input type="submit" name="button" id="button" value="提交" />
    </div>
    </form>
    </html>
      

  9.   

    q.html
    <script language='javascript'>var xmlHttp;function getXMLHttpRequest(){
      
      if(window.ActiveXObject){
        try {
          xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e){
          try{
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
          }
          catch(e){
            xmlHttp = false ;
          }
        }
      }
      else if(window.XMLHttpRequest)
        xmlHttp = new XMLHttpRequest();
      return xmlHttp;
    }getXMLHttpRequest();function sendRequest(){
     var xmlHttp = getXMLHttpRequest();
     var starttime = document.getElementById('starttime').value;
     var endtime = document.getElementById('endtime').value;
     var type = document.getElementById('type').value; var url = 'query_mobile.php'; if (!xmlHttp){
       return false;
      }
      
      xmlHttp.onreadystatechange = getResponse;

      
      xmlHttp.open('POST',url,true);
      xmlHttp.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); 
      xmlHttp.send('starttime='+escape(starttime)+'&endtime='+escape(endtime)+'&type='+escape(type));
    }function getResponse(){
    if(xmlHttp.readyState < 4){
    document.getElementById('status').innerHTML = 'waiting...';
    }
        if(xmlHttp.readyState == 4){
    if(xmlHttp.status == 200){
    response = xmlHttp.responseText;
    document.getElementById('status').innerHTML = unescape(response);
    }
    else
    {
    document.getElementById('status').innerHTML = 'error!';
    }
     }
    }window.onload = function(){
    document.onkeypress = keypress;
    }//兼容ie和firefox
    function keypress(evt){
    var e = evt? evt : window.event;
    if(e.keyCode == 13)
    sendRequest();
    }
    </script>
    <script type="text/javascript" language="javascript" src="calendar.js"></script>起始时间:<input type='text' name='starttime' onFocus="setday(this);"/>&nbsp;&nbsp;&nbsp;结束时间:<input type='text' name='endtime' onFocus="setday(this);" />&nbsp;&nbsp;&nbsp;状态类型:<select name='type'><option value='1'>1</option><option value='2'>2</option><option value='3'>3</option><option value='4'>4</option><option value='5'>5</option><option value='6'>6</option><option value='7'>7</option></select>&nbsp;&nbsp;&nbsp;<input type="button" id="checkmobile" value="query" onclick="sendRequest()" /><br/><br/>
    <br/><div id="status" ></div>
    query_mobile.php
    <?php
    function escape($str) { 
      preg_match_all("/[\x80-\xff].|[\x01-\x7f]+/",$str,$r);
      $ar = $r[0];
      foreach($ar as $k=>$v) { 
        if(ord($v[0]) < 128) 
          $ar[$k] = rawurlencode($v);
        else 
          $ar[$k] = "%u".bin2hex(iconv("GB2312","UCS-2",$v));
      } 
      return join("",$ar);
    } function unescape($str) { 
      $str = rawurldecode($str);
      preg_match_all("/(?:%u.{4})|.+/",$str,$r);
      $ar = $r[0];
      foreach($ar as $k=>$v) { 
        if(substr($v,0,2) == "%u" && strlen($v) == 6) 
          $ar[$k] = iconv("UCS-2","GB2312",pack("H4",substr($v,-4)));
      } 
      return join("",$ar);
    }$conn = mysql_connect("localhost","xxx","xxx");
    mysql_select_db("cp",$conn);
    mysql_query('set names gbk',$conn);$type = $_POST['type'];$sql = "select mobile,content,time,type from shuaka where smsid = 109 and type=$type";if(isset($_POST['starttime']) && !empty($_POST['starttime'])){
    $sql.=" and time>='".$_POST['starttime']."'";
    }if(isset($_POST['endtime']) && !empty($_POST['endtime'])){
    $sql.=" and time<='".$_POST['endtime']." 23:59:59'";
    }$res = mysql_query($sql,$conn);
    $total = mysql_numrows($res);
    $cnt = 0;
    ?>
    <?php
    if($total > 0){
    echo "<table width=100% border=1>";
    echo escape("<tr bgcolor='#aaaaaa'><td><strong>total</strong></td><td colspan=3>".$total."</td></tr>");
    echo escape("<tr bgcolor='#aaaaaa'><td><strong>mobile</strong></td><td><strong>content</strong></td><td><strong>time</strong></td><td><strong>type</strong></td></tr>");
    while($data = mysql_fetch_array($res)){
    if($cnt % 2 == 0)
    $color='#cccccc';
    else
    $color='#aaffaa';
    echo escape("<tr bgcolor=".$color."><td width=10%>".$data['mobile']."</td><td width=20%>".$data['content']."</td><td width=20%>".$data['time']."</td><td width=20%>".$data['type']."</td></tr>");
    $cnt++;
    }
    echo "</table>";
    }
    else
    echo "<H1>no data!</H1>";mysql_close($conn);
    ?>