⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 authmain.php

📁 《PHP和MySQL Web开发》(第三版) Source
💻 PHP
字号:
<?phpsession_start();if (isset($_POST['userid']) && isset($_POST['password'])){  // if the user has just tried to log in  $userid = $_POST['userid'];  $password = $_POST['password'];  $db_conn = new mysqli('localhost', 'webauth', 'webauth', 'auth');  if (mysqli_connect_errno()) {   echo 'Connection to database failed:'.mysqli_connect_error();   exit();  }  $query = 'select * from authorised_users '           ."where name='$userid' "           ." and password=sha1('$password')";  $result = $db_conn->query($query);  if ($result->num_rows >0 )  {    // if they are in the database register the user id    $_SESSION['valid_user'] = $userid;      }  $db_conn->close();}?><html><body><h1>Home page</h1><?   if (isset($_SESSION['valid_user']))  {    echo 'You are logged in as: '.$_SESSION['valid_user'].' <br />';    echo '<a href="logout.php">Log out</a><br />';  }  else  {    if (isset($userid))    {      // if they've tried and failed to log in      echo 'Could not log you in.<br />';    }    else     {      // they have not tried to log in yet or have logged out      echo 'You are not logged in.<br />';    }    // provide form to log in     echo '<form method="post" action="authmain.php">';    echo '<table>';    echo '<tr><td>Userid:</td>';    echo '<td><input type="text" name="userid"></td></tr>';    echo '<tr><td>Password:</td>';    echo '<td><input type="password" name="password"></td></tr>';    echo '<tr><td colspan="2" align="center">';    echo '<input type="submit" value="Log in"></td></tr>';    echo '</table></form>';  }?><br /><a href="members_only.php">Members section</a></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -