我正在学习PHP,并尝试使用PHP更改innerHtml
标记的<p/>
。
问题是我不知道为什么我的一个PHP变量能工作而另一个变量却不能工作。
我遇到的问题在最后的if
语句中; $check
变量没有被打印,但是当用另一个变量$pin
替换它时,它就起作用了。
</header>
<head>
<h1> MD5 cracker</h1>
</head>
<body>
<p>This application takes an MD5 hash of a four digit pin and check all 10,000 possible four digit PINs to determine the PIN.</p><br/>
<p id='deb'>Debug Output:<br/></p>
<p id='pin'>PIN: Not found </p>
<form method='POST'>
<input type='text' name='md5' value="">
<input type='submit' value='Crack MD5'>
</form>
<?php
$count=0;
$pin_list=array();
$pin_digits=array(0,1,2,3,4,5,6,7,8,9);
if (isset($_POST['md5'])) {
$md5= $_POST['md5'];
foreach ($pin_digits as $d1){
foreach ($pin_digits as $d2){
foreach ($pin_digits as $d3){
foreach ($pin_digits as $d4){
$pin= $d1 . $d2.$d3.$d4;
$check=hash('md5',$pin);
if ( $check==$md5){
echo "<script>
document.getElementById('pin').innerHTML='PIN: '+$pin;
</script>";
break;
}
if ($count<15) {
echo "<script>
document.getElementById('deb').innerHTML=$check;
</script>";
$count+=1;
}
}
}
}
}
}
?>
</body>
答案 0 :(得分:1)
尝试一下,您忘记了.innerHTML='$check';
上的引号
<body>
<p>This application takes an MD5 hash of a four digit pin and check all 10,000 possible four digit PINs to determine the PIN.</p><br/>
<p id='deb'>Debug Output:<br/></p>
<p id='pin'>PIN: Not found </p>
<form method='POST'>
<input type='text' name='md5' value="">
<input type='submit' value='Crack MD5'>
</form>
<?php
$count=0;
$pin_list=array();
$pin_digits=array(0,1,2,3,4,5,6,7,8,9);
if (isset($_POST['md5'])) {
$md5= $_POST['md5'];
foreach ($pin_digits as $d1){
foreach ($pin_digits as $d2){
foreach ($pin_digits as $d3){
foreach ($pin_digits as $d4){
$pin= $d1 . $d2.$d3.$d4;
$check=hash('md5',$pin);
if ( $check==$md5){
echo "<script>
document.getElementById('pin').innerHTML='PIN: '+$pin;
</script>";
break;
}
if ($count<15) {
echo "<script>
document.getElementById('deb').innerHTML='$check';
</script>";
$count+=1;
}
}
}
}
}
}
?>
</body>
答案 1 :(得分:0)
JS代码应类似于document.getElementById('str').innerHTML = 'string';
,因此请更新您的php源,然后一切正常。喜欢
echo "<script>document.getElementById('pin').innerHTML='PIN: {$pin}';</script>";
echo "<script>document.getElementById('deb').innerHTML='{$check}';</script>";