<?php
//Session
session_start();
session_name('hash_gen');
if(!isset($_GET['hashtype']))
$_GET['hashtype'] = "";
if(isset($_GET['clean']))
$_SESSION['str_t'] = array();
//Xml
echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml" />
<title>PHP Hash</title>
<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
</head>
<body class="center">
<h1>PHP Hash</h1>
<form method="get" action="hash.php">
<div class="hash">
Hash type :
<select name="hashtype">
<?php
foreach(hash_algos() as $Val)
{
echo "<option value=\"".$Val."\"";
if($_GET['hashtype'] == $Val)
echo " selected=\"selected\"";
echo ">".$Val."</option>\n";
}
?>
</select>
</div>
<div class="hash">
Hash String : <input type="text" name="str" <?php if(isset($_GET['str'])) echo "value=\"".$_GET['str']."\""; ?>/>
</div>
<div class="hash_s">
<input type="submit" value="Valider" />
<a href="hash.php?clean=true">Reset</a>
</div>
</form>
<?php
if(isset($_GET['hashtype']) && array_search($_GET['hashtype'], hash_algos()) !== false)
{
?>
<table class="hash_res">
<tr>
<th>Original string</th><th>Hashed string</th><th>String lenght</th>
</tr>
<?php
$_SESSION['str_t']["azerty"] = true;
$_SESSION['str_t']["gnu"] = true;
if(isset($_GET['str']) && $_GET['str'] != "")
{
if(is_array($_GET['str']))
foreach($_GET['str'] as $val)
$_SESSION['str_t'][$val] = true;
else
$_SESSION['str_t'][$_GET['str']] = true;
}
$class = false;
foreach($_SESSION['str_t'] as $str => $val)
{
$class = !$class;
?>
<tr class="<?php echo ($class)?"line1":"line2"; ?>">
<td><?php echo $str; ?></td>
<td><?php echo $hashed = hash($_GET['hashtype'], $str); ?></td>
<td><?php echo strlen($hashed); ?></td>
</tr>
<?php
}
?>
</table>
<?php
}
?>
<hr />
<p>
<a href="http://validator.w3.org/check?uri=referer">
<img src="http://www.w3.org/Icons/valid-xhtml11-blue"
alt="Valid XHTML 1.1" height="31" width="88" />
</a>
</p>
</body>
</html>