Bot*_*tyZ 1 php mysql syntax-error scramble
我想将软件许可证密钥存储在我的mysql数据库的一个字段中,但我希望以乱码格式存储许可证号,这样如果数据库被泄露,许可证密钥将无法使用.
许可证密钥字段有3种可能的方案:
我想在存储之前加扰许可证,然后在登录后向用户显示时,再次运行相同的加扰功能以解密许可证.
我想我需要先检查许可证的格式.
我设置了以下内容:
function scramble($scramblestr) {
// check string length
$length = strlen($scramblestr);
// if 10 digit license (all numbers)
if ($length == 10) {
$1st = substr($scramblestr, 0, 1);
$2nd = substr($scramblestr, 1, 1);
$3rd = substr($scramblestr, 2, 1);
$4th = substr($scramblestr, 3, 1);
$5th = substr($scramblestr, 4, 1);
$6th = substr($scramblestr, 5, 1);
$7th = substr($scramblestr, 6, 1);
$8th = substr($scramblestr, 7, 1);
$9th = substr($scramblestr, 8, 1);
$10th = substr($scramblestr, 9, 1);
// swap 3rd character with 7th / swap 5th character with 9th
$scramblestr = $1st . $2nd . $7th . $4th . $9th . $6th . $3rd . $8th . $5th . $10th;
// if 25 digit license (with hyphen separators)
} elseif ($length == 29) {
$scramblestr = array_filter(explode('-', $scramblestr), 'strlen');
// swap 2nd & 4th sections
$scramblestr = $scramblestr[0] . "-" . $scramblestr[3] . "-" . $scramblestr[2] . "-" . $scramblestr[1] . "-" . $scramblestr[4];
// swap alpha characters 13 places in the alphabet
$scramblestr = str_rot13($scramblestr);
// if null or if stored incorrectly (for example if the license is not null but contains an invalid number of characters)
} else {
$scramblestr = "Unknown";
}
return $scramblestr;
}
Run Code Online (Sandbox Code Playgroud)
但是,这会导致以下服务器500错误:
PHP解析错误:语法错误,意外的'1'(T_LNUMBER),期望变量(T_VARIABLE)或'$'
这指向第一个子参考.但是,根据php.net,它应该是一个整数,用于标记字符串的长度.
有任何想法吗?
或者是否有更有效的方法来执行此操作?或者有没有人有任何替代方法可能适合?
"@Fred&CaptainCarl你们都是对的,我怎么能没有意识到...将$ st改为$ first等等...... - BottyZ"
提交答案:
这里的问题是你的变量以数值开头; 不能那样做.做一些事情$a1st,而不是$1st从一封信开始.
Stack上的参考文献你可以读一下:
| 归档时间: |
|
| 查看次数: |
276 次 |
| 最近记录: |