调用PHP登录功能

时间:2012-05-17 10:20:02

标签: php

这是我的HTML代码:

<html>
<head>
<title>Login</title>
</head>

<body>


<FORM NAME ="form1" METHOD ="POST" ACTION ="controller.php">

<input type = "text" name = "txtUsername" value = "testuser"><br>
<input type = "text" name = "txtPassword" value = "password"><br>

<Input type = 'Submit' Name ='Login' value="Login">

</FORM>

</body>
</html>

<?PHP

    include_once("controller/Controller.php");  

    function login($username,$password) {
            $controller = new Controller();  
            $controller->invoke("testUsername","testPassword");  
    }

?>

我可以帮助用两个输入框中的值调用PHP登录函数吗?

4 个答案:

答案 0 :(得分:2)

也许

$user = $_POST['txtUsername'];
$pass = $_POST['txtPassword'];

login($user, $pass); 

答案 1 :(得分:0)

我认为你应该这样做:

<?php

if (isset($_POST['Login'])) {
    login($_POST['txtUsername'],$_POST['txtPassword'])
}

当然,您需要在controller.php内处理请求。

答案 2 :(得分:0)

确定,您可以使用

if (isset($_POST['txtUsername'])&&isset($_POST['txtPassword'])) {
    $username = $_POST['txtUsername'];
    $password = $_POST['txtPassword'];
    login($username, $password);
} else {
    // some logic actions if there no values on txtUsername and txtPassword.
}

此外,我还建议你是否可以使用占位符属性而不是像......这样的值属性

<input type="text" name="txtUsername" placeholder="Username"><br>
<input type="password" name="txtPassword"><br>

答案 3 :(得分:-1)

<FORM NAME ="form1" METHOD ="POST" ACTION ="<?php echo $PHP_SELF;?>">

也:

if ( 'POST' == $_SERVER['REQUEST_METHOD'] )
{
  $user = $_POST['txtUsername'];
  $pass = $_POST['txtPassword'];

  login($user, $pass); 
}