[英]Search Base64 string in MySQL table using PHP
I asked this question yesterday, but I didn't get an answer and the question has been marked as duplicate, which is not. 昨天我问了这个问题 ,但没有得到答案,这个问题被标记为重复,不是。
I changed the "key" column name to "lic_key" and "keys" table name to "license_keys" because I understand they are reserved by MySQL. 我将“键”列名更改为“ lic_key”,将“键”表名更改为“ license_keys”,因为我知道它们是MySQL保留的。
This is my PHP code: 这是我的PHP代码:
<?php
require 'config.inc.php';
/* Connect to database and grab the keys */
@mysql_connect($g_mysql_host,$g_mysql_usr,$g_mysql_pass)
or die("Couldn't connect to database server");
@mysql_selectdb($g_mysql_db)
or die("Couldn't select database");
$key = mysql_real_escape_string($_GET["key"]);
$query = "SELECT * FROM `license_keys` WHERE `lic_key` = '$key'";
$result = mysql_query($query);
if ($result == "") exit("INVALID KEY");
else {
while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
echo $row['id'];
}
}
?>
This works only if the key does NOT contain the "+" character, and it outputs the specific "id" for the searched "license_key" . 仅当密钥不包含“ +”字符,并且为搜索到的“ license_key”输出特定的“ id”时,此方法才有效。 If the key contains "+" or is not found, the page remains blank (which is another problem that I have, because the script should output "INVALID KEY") .
如果键包含“ +”或找不到,则页面保持空白(这是我遇到的另一个问题,因为脚本应输出“ INVALID KEY”)。
The key strings are encrypted using AES128 in Base64. 密钥字符串在Base64中使用AES128加密。 Other keys have the "+" character, other not.
其他键带有“ +”字符,其他则没有。
Shortly, 不久,
kQcYqzQlsr4/MXJ1ySw7jQ== -- works.
CKVcua+aWlnK5qfKwcm6wA== -- does not work.
This script is only for personal usage, so I'm not scared about SQL injection. 该脚本仅供个人使用,因此我不担心SQL注入。
Thanks. 谢谢。
Thanks to @Barmar for clarifying the problem with "+" character in the URL. 感谢@Barmar澄清了网址中带有“ +”字符的问题。 To fix the problem with the blank page if the key is incorrect, I edited
要解决键不正确的空白页问题,我进行了编辑
if ($result == "") exit("INVALID KEY");
with 同
if (mysql_num_rows($result)==0) exit("INVALID KEY");
and now it works. 现在可以了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.