当前位置:Gxlcms > PHP教程 > 一个简单的php用户登陆模块

一个简单的php用户登陆模块

时间:2021-07-01 10:21:17 帮助过:19人阅读

  1. 登陆系统
  2. session_start();
  3. if ($_SESSION[username]) {
  4. ?>
  5. }else {
  6. ?>
  7. }
  8. ?>

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 "";
  13. }else {
  14. echo "