使用PHP在MySQL表中搜索Base64字符串 [英] 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.
我将"key"列名更改为"lic_key",将"keys"表名更改为"license_keys",因为我知道它们是MySQL保留的.
I changed the "key" column name to "lic_key" and "keys" table name to "license_keys" because I understand they are reserved by MySQL.
这是我的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'];
}
}
?>
仅当密钥不包含"+"字符时才有效,并且为搜索到的"license_key"输出特定的"id". 如果键包含"+"或未找到,则页面将保持空白(这是我遇到的另一个问题,因为脚本应输出"INVALID KEY").
This works only if the key does NOT contain the "+" character, and it outputs the specific "id" for the searched "license_key" . 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") .
在Base64中使用AES128对密钥字符串进行加密.其他键带有"+"字符,其他则没有.
The key strings are encrypted using AES128 in Base64. Other keys have the "+" character, other not.
很快,
kQcYqzQlsr4/MXJ1ySw7jQ== -- works.
CKVcua+aWlnK5qfKwcm6wA== -- does not work.
该脚本仅供个人使用,因此我不担心SQL注入.
This script is only for personal usage, so I'm not scared about SQL injection.
谢谢.
推荐答案
感谢@Barmar阐明了URL中带有"+"字符的问题. 要解决密钥不正确的空白页问题,我编辑了
Thanks to @Barmar for clarifying the problem with "+" character in the URL. To fix the problem with the blank page if the key is incorrect, I edited
if ($result == "") exit("INVALID KEY");
使用
if (mysql_num_rows($result)==0) exit("INVALID KEY");
现在可以使用了.
这篇关于使用PHP在MySQL表中搜索Base64字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!