我正在創建一個簡單的腳本,它在文本文件中搜索正確的組合,但它不起作用。我對所有問題都進行了故障排除,但所有部分都可以正常工作,但整個腳本仍然無法正常工作,我不知道如何修復它。代碼:<html><form><input type="text" name="input" placeholder="hash"><button type="submit">Crack!</button></form><?php$input = $_GET["input"]; // pulling input from url$hashes = file_get_contents("hashes.txt"); // loading hashes$hasharray = explode(";", $hashes); // separating hashcombos$arraynum = count($hasharray); // counting number of hashcombos// defining loop$loopnum = 0;while($loopnum < $arraynum) { $combo = $hasharray[$loopnum]; // selecting hashcombo $comboarray = explode("|", $combo); // separating hashcombo $text = $comboarray[0]; $hash = $comboarray[1]; // cecking if hash matches if($hash === $input) { echo("Hash: $hash"); echo("<br>"); echo("Text: $text"); } $loopnum = $loopnum + 1; // updating loop}?></html>示例 hashes.txt:test|example;example|test;
1 回答

揚帆大魚
TA貢獻1799條經驗 獲得超9個贊
您的文件包含換行符,它們也是不可見的字符。例如:
test|example;(newline here) example|test;
您使用 拆分文件中的行;
,但這不會刪除換行符??紤]到您問題中的評論,您的結果中有換行符導致比較失敗。也就是說,我建議在加載哈希以刪除換行符后立即使用以下解決方案:
$hashes = preg_replace("/[\r\n]/", "", $hashes);
這將產生如下字符串:
test|example;example|test;
您的其余代碼將按預期工作。
- 1 回答
- 0 關注
- 101 瀏覽
添加回答
舉報
0/150
提交
取消