Jump to content

[SOLVED] Problems with hash()


maexus

Recommended Posts

ajax.js:
[code]var xmlHttp

function showHash(str, tpe){
if (str.length==0){
document.getElementById("hash").innerHTML="Please select a hash type and enter a string."
return
}
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null){
alert ("Browser does not support HTTP Request")
return
}
var url="ajax.php"
url=url+"?q="+str
url=url+"&t="+tpe
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChanged(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
document.getElementById("hash").innerHTML=xmlHttp.responseText
}
}

function GetXmlHttpObject(){
var objXMLHttp=null
if (window.XMLHttpRequest){
objXMLHttp=new XMLHttpRequest()
}else if (window.ActiveXObject){
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}[/code]

ajax.php:
[code]<?php
$string = hash($_GET["t"],$_GET["q"]);

if (empty($string)){
$response="Please select a hash type before entering a string.";
}else{
$response=$string;
}

echo $response;
?>[/code]

index.php:
[code]<html>
<head>
<title>Instant Hasher</title>
<script src="ajax.js"></script>
<style type="text/css">
body {
cursor: default;
font-family: sans-serif;
}
span#hash {
padding: 3px;
border: 1px solid #000000;
background: #007FA5;
color: #ffffff;
}
</style>
</head>
<body>
<h1>Instant Hasher</h1>
<form>
<p>Hash Type: <select id="hashtype" <?php#onchange="showHash(this.value, getElementById('string').value)"?>>
<option value="md5" default="default">md5</option>
<option value="sha1">sha1</option>
<option value="sha256">sha256</option>
</select><p>
<p>String: <input type="text" id="string" size="50" onkeyup="showHash(this.value, getElementById('hashtype').value)"></p>
</form>
<pre><span id="hash">Please select a hash type and enter a string.</span></pre>
<h2>Why make this?</h2>
<p>This little script really serves two needs. To learn a little about Ajax and JS also, there are times I need to see what the hash of a string looks like right away, this is very fast at that.</p>
</body>
</html>[/code]
encodeURL is a Javascript function as can be seen [url=http://www.w3schools.com/jsref/jsref_encodeURI.asp]here[/url]. But that page says you have to use the function encodeURIComponent() to encode the characters [b], / ? : @ & = + $ #[/b].

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.