如何在php浏览器中使用url登录?
如何在php浏览器中使用url登录? 我想知道是否有一种方法可以通过向url传递用户名和密码来登录。。 我在网上搜索,但实际上什么都没用 我知道这不是一个好的行为,但它将在内部应用程序中使用。 非常感谢您的帮助如何在php浏览器中使用url登录?,php,Php,如何在php浏览器中使用url登录? 我想知道是否有一种方法可以通过向url传递用户名和密码来登录。。 我在网上搜索,但实际上什么都没用 我知道这不是一个好的行为,但它将在内部应用程序中使用。 非常感谢您的帮助 这是我的登录码 elseif (isset($_GET['act']) && $_GET['act'] == 'login' && is_ajax() && isset($_POST['email'])
这是我的登录码
elseif (isset($_GET['act'])
&& $_GET['act'] == 'login'
&& is_ajax()
&& isset($_POST['email'])
&& isset($_POST['password'])
&& !empty($_POST['email'])
&& !empty($_POST['password'])
) {
$cookie_time = time() + (86400 * 30 * 12);
$status = 1;
$error = '';
// change character set to utf8 and check it
if (!mysqli_set_charset(db_connect(), 'utf8')) {
$error = mysqli_error(db_connect());
$status = 0;
}
// if no connection errors (= working database connection)
if (!mysqli_connect_errno(db_connect())) {
// escape the POST stuff
$email = db_escape($_POST['email']);
$result_of_login_check = db_query("SELECT `ID` ,`username`, `password`, `email` FROM `members` WHERE `email` = '$email' || `username` = '$email'");
// if this user exists
if (mysqli_num_rows($result_of_login_check) == 1) {
// get result row (as an object)
$result_row = mysqli_fetch_assoc($result_of_login_check);
// User ID
$user_id = $result_row['ID'];
// the hash of that user's password
if (password_verify($_POST['password'], $result_row['password'])) {
$salt = bin2hex(openssl_random_pseudo_bytes(512));
$hash = password_hash($salt, PASSWORD_DEFAULT);
$token = bin2hex(openssl_random_pseudo_bytes(32));
db_query("UPDATE `members` SET `salt` = '$salt', `token` = '$token' WHERE `ID` = $user_id");
$userid = ($user_id + 412) * 137; // Crypt User ID with some basic math operations
setcookie('key', $hash, $cookie_time, '/'); // Set key cookie
setcookie('user_id', $userid, $cookie_time, '/'); // Set user_id Cookie
setcookie('login_token', md5(uniqid(mt_rand(), true)), $cookie_time, '/'); // Set user_id Cookie
} else {
$error = 'Wrong password. Please try again.';
$status = 0;
}
} else {
$error = 'We could not find any user.';
$status = 0;
}
} else {
$error = 'Database connection problem.';
$status = 0;
}
echo json_encode(
array(
'stat' => $status,
'error' => $error,
)
);
}
您可以通过如下URL传递
用户名/电子邮件
和密码
来实现https://example.com/loginpage.php?u=YOUR_USERNAME&p=YOUR_PASSWORD,并可以在PHP代码中收集凭据,如下所示:
<?php
$username = $_GET['u'];
$password = $_GET['p'];
我想这段代码可以帮助你
<?php
if(isset($_GET['act']) && $_GET['act'] == 'login' && isset($_GET['email']) && isset($_GET['password']) ){
$result_of_login_check = db_query("SELECT * FROM members WHERE email = '$email' AND password = '$password'");
if (mysqli_num_rows($result_of_login_check) == 1) {
$result_row = mysqli_fetch_assoc($result_of_login_check);
$user_id = $result_row['ID'];
$_SESSION["user"] = $user_id;
header("Location:/profile");
}
}
在您的页面中,您将匹配数据库中的用户名和密码以检查数据库中是否有用户,不要使用mysql\u real\u escape\u string
!请改用准备好的语句。不要在数据库中存储明文密码!使用密码\u hash()
您可以通过URL登录,但这是非常不推荐的。URL是公共的,无法加密,这意味着您的密码在使用时就会泄露。这将立即危及每个帐户。它仅供内部使用。。请阅读我的解释,直到你网络上的每个人都知道所有密码。你为什么要这么做?这只是为了实验性的用途我想知道这个概念>>你能帮上忙吗