我有一个固定的用户名密码和一个可变文本。
这是第一种方法,但并不安全:
<form action="http://site.com/foo.php" method="post">
<input type="hidden" name="username" value="user123" />
<input type="hidden" name="password" value="pass123" />
<input type="text" name="text" />
<input type="submit" />
</form>
这是第二种方法请完成以下步骤:
index.html
<form action="foo.php" method="post">
<input type="text" name="text" />
<input type="submit" />
</form>
foo.php
$username = "user123";
$password = "pass123";
$text = $_POST["text"];
$url = "http://site.com/foo.php?text=".$text."&password=".$password."&username=".$username;
如何发布$ url安全? (没有HTTPS)
最佳答案
更新:
没有HTTPS,您将无法安全登录。
这是非常不安全的,并且不会阻止人们登录
如果他们拦截哈希值。
只需使用HTTPS。
使用MD5 function。
例如
$url = "http://example.com/foo.php?text=".$text."&password=".md5($password)."&username=".$username;
然后在接收站点(
http://example.com/foo.php?...
)上,使用实际密码的哈希值(MD5)检查收到的密码。例:
发送文件:
$username = "user123";
$password = "pass123";
$text = $_POST["text"];
$url = "http://example.com/foo.php";
$data = "text=".$text."&password=".md5($password)."&username=".$username;
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($handle);
curl_close($handle);
if($result) {
// Success
} else {
// Failed
}
接收文件:
$username = $_POST["username"];
$password = $_POST["password"];
// Insert code here to escape the username with mysqli_real_escape_string,
// then retrieve data from database with MySQLi.
if($password == md5($db_password)) {
// Correct password
} else {
echo 'Incorrect password.';
}
unset($username, $password, $db_password); // For security, remove variables from memory