1

I have a database and a login form and want to write a php script that validates the login.

How are the types' data access and used?

For example, how do I access the input entered from the user in these elements.

<p><input type="text" name="login" value="" placeholder="Username or Email"></p>
<p><input type="password" name="password" value="" placeholder="Password"></p>

I want to use the login and password for validation. How can these be passed to a php script?

EDIT: I set the action to

<form method="post" action="loginVerification.php">

and when I enter the fields and submit the values, my OS wants to save the loginVerification.php. When I save it I dont get the echo.

I have this in the php file

<?php
 echo $_POST['login'];
 echo $_POST['password'];

How do I write the logs to a file in php, or is there a way to do runtime verification for php?

Edit 2:

  <div class="container">
<section class="login">
  <h1>Login</h1>
  <form method="post" action="loginVerification.php">
    <p><input type="text" name="login" value="" placeholder="Username or Email"></p>
    <p><input type="password" name="password" value="" placeholder="Password"></p>
    <p class="remember_me">
      <label>
        <input type="checkbox" name="remember_me" id="remember_me">
        Remember me on this computer
      </label>
    </p>
    <p class="submit"><input type="submit" name="commit" value="Login"></p>
  </form>
</section>

<section class="login-help">
  <p>Lost password? <a href="index.html">Click here to reset it</a>.</p>
</section>

4

5 回答 5

1

If your form method is post, these variables would be accessible through $_POST['login'] and $_POST['password'].

于 2012-05-05T18:26:39.957 回答
1

These fields should be part of a <form> element, such as the following:

<form method="POST" action="process.php">
  <!-- input elements here -->
  <input type="submit" />
</form>

Submitting the form will pass your data to your action location. In this case, to a script on the server called "process.php". Assuming your method is POST, from within process.php you could access your input fields via the $_POST global array:

<?php

  // Show value of <input type="text" name="foo" />
  echo $_POST['foo'];

?>
于 2012-05-05T18:28:08.520 回答
1

有两种方法可以从 HTML 表单中获取数据:

  • 邮政

HTML 表单标签:

<form method="post" action="some.php">
<input type="text" name="username" size="20"/>
<input type="password" name="password" size="20"/>
</form>

要访问 some.php 中的字段值,您可以使用$_POST超级全局。例如:$_POST['username']

  • 得到

HTML 表单标签:

<form method="get" action="some.php">
<input type="text" name="username" size="20"/>
<input type="password" name="password" size="20"/>
</form>

要访问 some.php 中的字段值,您可以使用$_GET超级全局。例如:$_GET['username']

现在要创建一个登录系统,您需要创建一个用户名和密码数据库:

username | password
----------------------
abc      | passcode!@#
xyz      | passco#$%^^

对于登录,您可以使用会话保持用户跨多个页面(Web 应用程序)登录。在登录脚本中,通过查看表来检查用户是否有效,并使用$_SESSION超级全局变量为会话变量设置一些值。您可以在 Web 应用程序的任何页面中访问该变量,因为需要在每个页面中使用以下命令启动会话:

session_start()

功能。在每个页面上,必须检查会话变量的值,如果它是有效的,则显示页面,否则将用户引导到登录页面。

在这里您可以找到有关会话的信息:http: //php.net/manual/en/ref.session.php

于 2012-05-05T18:41:29.680 回答
0

Form input values are passed via POST typically. From your PHP, you access those values using the $_POST superglobal like this:

$login = $_POST['login'];
$password = $_POST['password'];

The array key in the $_POST array is what you set name to in your HTML element like name="login".

When using this value, be aware that it comes straight from your user and should not be trusted. If you don't filter it prior to using it with database operations, you run the very real risk of becoming a victim of SQL injection leading to your site being compromised.

于 2012-05-05T18:27:18.870 回答
0

in your php file try this

echo $_REQUEST['login'];
echo $_REQUEST['password'];
于 2012-05-05T18:27:47.100 回答