maexus Posted December 28, 2006 Share Posted December 28, 2006 hash('sha256', $string);That works just fine until I enter # anywhere in the string, it produces:Warning: hash() [function.hash]: Unknown hashing algorithm: in C:\Program Files\xampp\htdocs\ajax\ajax.php on line 2Tips? Link to comment https://forums.phpfreaks.com/topic/32103-solved-problems-with-hash/ Share on other sites More sharing options...
maexus Posted December 28, 2006 Author Share Posted December 28, 2006 bump :) Link to comment https://forums.phpfreaks.com/topic/32103-solved-problems-with-hash/#findComment-149048 Share on other sites More sharing options...
Psycho Posted December 29, 2006 Share Posted December 29, 2006 Works fine for me. Pehaps you need to show a little more of your code.This[code]<?php$string = "#A#B#C#";$hash = hash('sha256', $string);echo $hash;?>[/code]Outputs this:7ba8fc9f18d0e5f7801a13e9029d385c46b6b379edf4b3c879d81560bfe83612 Link to comment https://forums.phpfreaks.com/topic/32103-solved-problems-with-hash/#findComment-149063 Share on other sites More sharing options...
maexus Posted December 29, 2006 Author Share Posted December 29, 2006 ajax.js:[code]var xmlHttpfunction 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] Link to comment https://forums.phpfreaks.com/topic/32103-solved-problems-with-hash/#findComment-149075 Share on other sites More sharing options...
mainewoods Posted December 29, 2006 Share Posted December 29, 2006 because you are passing the value to be hashed to php through the url using ajax, you need to encode it: [color=red] encodeURI() [/color]before putting it on the url: [code]url=url+"?q="+encodeURI(str); [/code] Link to comment https://forums.phpfreaks.com/topic/32103-solved-problems-with-hash/#findComment-149089 Share on other sites More sharing options...
maexus Posted December 29, 2006 Author Share Posted December 29, 2006 Is encodeURI a JS function? I know it's function in PHP. If it is php... how do I slip into php in a js file and have php interact with js variables? The reason I ask is because I used your example and it didn't work. Link to comment https://forums.phpfreaks.com/topic/32103-solved-problems-with-hash/#findComment-149097 Share on other sites More sharing options...
maexus Posted December 29, 2006 Author Share Posted December 29, 2006 bump Link to comment https://forums.phpfreaks.com/topic/32103-solved-problems-with-hash/#findComment-149174 Share on other sites More sharing options...
kenrbnsn Posted December 29, 2006 Share Posted December 29, 2006 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 Link to comment https://forums.phpfreaks.com/topic/32103-solved-problems-with-hash/#findComment-149189 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.