开发者

the login code of php

<?php
 //Start session
 session_start();

 //Define the users and passwords.
 $users = array(
   array("username1","password1"),
   array("username2","password2"),
   array("username2","password2") 
 );

 //Define the log in page if login failed.
 $exitpage = "login.htm";

This code is from the internet (user开发者_如何学Python login code ). But I don't know this part means. Why it declares three users? And why the last two ones are same?


This code is providing a harcoded list of users, as a "sample" datasource.

The username present twice is a mistake.


For your clarification the meaning of the code is an array with array items, each including two items (username and password). Meaning:

array (
 [0] => Array
     (
         [0] => username1
         [1] => password1
     )

 [1] => Array
     (
         [0] => username2
         [1] => password2
     )

 [2] => Array
     (
         [0] => username2
         [1] => password2
     )
 )

The duplicate is most likely a typo, as already mentioned.


That seems to be a badly written example.

The repeat of username2, password2 is probably a typo. I would assume it was meant to be username3 and password3.


maybe two typos? Just change the last line to array("username3","password3") and everything makes sense! ;)


Its not good tutorial for education. At least $users array can be declared as

$users = array(
   // define known login => password pairs
   array("username1" => "password1"),
   array("username2" => "password2"),
   array("username3" => "password3") 
);

And later use isset() or array_key_exists() to check Login/Pass:

$user = $_POST['user'];
$pass = $_POST['pass'];
if (isset($users[$user]) AND $users[$user] == $pass)
{
   // successfull login
   // store username instead of boolean flag
   $_SESSION['logged_in'] = $user;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜