A simple php user login module

WBOY
Release: 2016-07-25 08:59:20
Original
1010 people have browsed it
  1. 登陆系统
  2. session_start();
  3. if ($_SESSION[username]) {
  4. ?>
  5. 当前用户
  6. }else {
  7. ?>
  8. 用户
    密码
  9. }
  10. ?>
复制代码

2,config.php

  1. $dbhost="localhost";
  2. $dbuser="root";
  3. $dbpassword="123456";
  4. $dbname="auth";
  5. $conn=mysql_connect("$dbhost","$dbuser","$dbpassword") or die('不能连接服务器'.mysql_error());
  6. mysql_select_db("$dbname",$conn) or die("数据库访问错误".mysql_errno());
  7. mysql_query("set names gb2312");
  8. ?>
复制代码

3,userlogin.php

  1. 登陆系统_bbs.it-home.org
  2. session_start();
  3. require("config.auth.php");
  4. if ($_POST[submit]) {
  5. $sql="select * from userinfo where username = '$_POST[username]' and password = '$_POST[password]'";
  6. $result=mysql_query($sql);
  7. $numrows=mysql_num_rows($result);
  8. if ($numrows == 1) {
  9. $row=mysql_fetch_assoc($result);
  10. $_SESSION[username]=$row[username];
  11. //echo $_SESSION[username];
  12. echo "<script>alert('登陆成功!');window.location.href='left.php';</script>";
  13. }else {
  14. echo "
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!