PHP4中session登录页面的应用

yipeiwu_com4年前PHP代码库
<?php
//这个脚本是用来给用户输入口令,并判断口令是否正确的。
//如果正确则转到欢迎页面。
if ($login){
    include("../include/config.inc.php3");
    session_start();
    $right_enter='0';
    $query="select * from user_define where user_login='$user_login' and user_pass=password('$user_pass')";
    $result=@mysql_query($query,$dbconnect);
    if ($user_array=@mysql_fetch_array($result)){
        $user_id=$user_array[user_id];
        $user_name=$user_array[user_info];
        session_register("user_id");
        session_register("user_name");
        session_register("user_array");
        if(($user_array[ticket_day]) and ($user_array[ticket_num])){
            $right_enter='1';
        }
        else{
            $error_message="对不起,您没有订票的权限!";
        }
    }
    else{
        $error_message="错误!用户名错,或口令错。请重新输入。";
    }
    $log_time=date("Y-m-d H:i:s");
    $query="insert into log_record (log_time,user_login,remote_addr,right_enter,enter_function) values ('$log_time','$user_login','$REMOTE_ADDR','$right_enter','1')";
    @mysql_query($query,$dbconnect);
    if($right_enter){
        Header("Location: welcome_reserve.php3");
        exit;
    }
}
if($logout){
    session_start();
    session_unregister("user_id");
    session_unregister("user_name");
    session_unregister("user_array");
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
    <title>用户登录</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" type="text/css" href="../include/njz_common.css">
</head><body>
<p> </p>

<form name="form1" method="post" action="<?php echo $PHP_SELF; ?>" >
  <table width="289" border="1" cellspacing="0" cellpadding="1" bordercolor="#999999" align="center">
    <tr bgcolor="#999999"> 
      <td> 
        <div align="center"><font color="#FFFFFF" size="4">用户登录</font></div>
      </td>
    </tr>
    <tr>
      <td>
        <table width="267" border="0" cellspacing="0" cellpadding="5" align="center">
          <tr> 
            <td width="94"> 
              <div align="right">用户:</div>
            </td>
            <td width="169"> 
              <input type="text" name="user_login" size="16" maxlength="16" value="<?php echo $user_login; ?>">
            </td>
          </tr>
          <tr> 
            <td width="94"> 
              <div align="right">口令:</div>
            </td>
            <td width="169"> 
              <input type="password" name="user_pass" size="16" maxlength="16">
            </td>
          </tr>
          <tr> 
            <td colspan="2"> 
              <div align="center"> 
                <input type="submit" name="login" value=" 登  录 ">
                <input type="button" name="return_index" value="返回首页" onClick="form1.action='../include/goto_page.php3?dist_page=../main.php3';form1.submit();return;">
              </div>
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
</form>
<?php
if($error_message) echo "<center><font color='#ff0000'>$error_message</font></center>";
?>
<SCRIPT language="JavaScript">document.form1.user_login.focus();
</SCRIPT>
<p> </p>
<?php include("../footer.php3"); ?>
</body>
</html>

相关文章

PHP正则匹配日期和时间(时间戳转换)的实例代码

先来一个比较简单实用的代码 日期YYYY-MM-DD $str = ''; $isMatched = preg_match('/^\d{4}(\-|\/|.)\d{1,2}\1\d{...

PHP 观察者模式深入理解与应用分析

PHP 观察者模式深入理解与应用分析

本文实例讲述了PHP 观察者模式。分享给大家供大家参考,具体如下: 用模式开发的优点是,能让我们的逻辑结构以及代码更加清晰,便于维护! 而我们为什么要用 “观察者模式”?这就需要从实际运...

PHP类与对象后期静态绑定操作实例详解

本文实例讲述了PHP类与对象后期静态绑定操作。分享给大家供大家参考,具体如下: 做项目是后期静态绑定非常有用。比如service层单例模式,使用后期静态绑定就非常好实现。 自 PHP 5...

php查找字符串中第一个非0的位置截取

php查找字符串中第一个非0的位置截取

话不多说,请看代码: $str = '00000000000000000000000000000000000000001234506'; $preg = '/[0]*/'; $res...

php中unserialize返回false的解决方法

本文实例讲述了php中unserialize返回false的解决方法,分享给大家供大家参考。具体方法如下: php 提供serialize(序列化) 与unserialize(反序列化)...