I have a html file that sends POST information to another php file, but the php file wont return XML
phpinfo.phpHTML Code:<HTML> <head> <script type="text/javascript"> <!-- function createRequestObject() { var ro; if (navigator.userAgent.search(/MSIE/) >= 0) { ro = new ActiveXObject("Microsoft.XMLHTTP"); } else { ro = new XMLHttpRequest(); } return ro; } var request = createRequestObject(); function reverseMd5(md5) { if (md5.length > 0) { request.open('get', 'md5.php?hash=' + escape(md5)); request.onreadystatechange = handleReverseMd5; request.send(null); } } function handleReverseMd5() { if (request.readyState == 4) // Finished { var response = request.responseXML; var root = response.documentElement; var hash = root.getElementsByTagName('hash'); var string = root.getElementsByTagName('string'); var error = root.getElementsByTagName('error'); var returnString; if (hash.length) { hash = hash[0].firstChild.data; } if (string.length) { string = string[0].firstChild.data; } if (error.length) { error = error[0].firstChild.data; } if (error.length > 0) { returnString = '<p class="error">'; returnString += error; returnString += '<\/p>'; } else { returnString = '<p>The given MD5 hash reverses to:<\/p>'; returnString += '<p class="result">' + string + '<\/p>'; } document.getElementById('return').innerHTML = returnString; } else if (request.readyState == 1) // Loading { document.getElementById('return').innerHTML = '<p class="status">Loading from server . . .<\/p>'; } } function getMd5(str) { if (str.length > 0) { var md5 = hex_md5(str); document.getElementById('md5').value = md5; reverseMd5(md5); } } function disableReturnKey(evt) { var evt = (evt) ? evt : ((event) ? event : null); var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); if ((evt.keyCode == 13) && (node.type=="text")) { return false; } } document.onkeypress = disableReturnKey; // --> </script> </head> <body> <p>This form uses several MD5 databases to look up an MD5 hash and return its original counterpart. You may use the second field to first generate an MD5 hash of a string to use in a reverse lookup.</p> <div id="results"> <h2>Results</h2> <div id="return"><p>The results of the reversed hash will be displayed here.</p></div> </div> <div id="form-area"> <form id="md5form" method="post" action="phpinfo.php"> <p> <label for="md5">Hash to reverse:</label><br /> <input type="text" name="md5" id="md5" onblur="reverseMd5(document.getElementById('md5').value);" /> <input type="button" name="reverse" id="reverse" value="Reverse Hash" onclick="reverseMd5(document.getElementById('md5').value);" /> </p> <p> <label for="string">String to convert to an MD5 hash:</label><br /> <textarea name="string" id="string" rows="10" cols="50" onblur="getMd5(document.getElementById('string').value);"></textarea><br /> <input type="button" name="create" id="create" value="Create MD5 Hash" onclick="getMd5(document.getElementById('string').value);" /> </p> <p><input type="reset" value="Clear Form" onclick="document.getElementById('return').innerHTML = '<p>The results of the reversed hash will be displayed here.</p>';" /></p> </form> </div> <hr /> </body> </html>
PHP Code:<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
require_once 'HTTP/Request.php';
/* MD5 databases we're using; corresponds to a function name */
$md5_stores = array(
'rednoize', // md5.rednoize.com
'schwett', // www.schwett.com
'crysm_us', // us.md5.crysm.net
'crysm_nz', // nz.md5.crysm.net
'gdata' // gdataonline.com
);
/* Provides escaping for output to XML */
function escape_xml($input)
{
$output = '<![CDATA[';
$output .= $input;
$output .= ']]>';
return $output;
}
/* md5.rednoize.com */
function md5_rednoize($str)
{
$xml = simplexml_load_file("http://md5.rednoize.com/?q={$str}&xml");
$string = (string) $xml->ResultString;
if (strlen($string) > 0)
{
return $string;
}
}
/* www.schwett.com */
function md5_schwett($str)
{
$xml = simplexml_load_file("http://www.schwett.com/md5/xml.php?hash={$str}");
$string = (string) $xml->password->cleantext;
if (strlen($string) > 0)
{
return $string;
}
}
/* us.md5.crysm.net */
function md5_crysm_us($str)
{
$data = '';
$req =& new HTTP_Request("http://us.md5.crysm.net/find?md5={$str}");
if (!PEAR::isError($req->sendRequest()))
{
$data = $req->getResponseBody();
}
if (preg_match('!<li>(.*?)</li>!', $data, $m))
{
return $m[1];
}
}
/* nz.md5.crysm.net */
function md5_crysm_nz($str)
{
$data = '';
$req =& new HTTP_Request("http://nz.md5.crysm.net/find?md5={$str}");
if (!PEAR::isError($req->sendRequest()))
{
$data = $req->getResponseBody();
}
if (preg_match('!<li>(.*?)</li>!', $data, $m))
{
return $m[1];
}
}
/* gdataonline.com */
function md5_gdata($str)
{
$data = '';
if (!empty($_SERVER['HTTP_USER_AGENT']))
{
$ua = strtr($_SERVER['HTTP_USER_AGENT'], "\r\n", ' '); /* CRLF protection */
}
else
{
$ua = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4';
}
$req =& new HTTP_Request('http://gdataonline.com/seekhash.php');
$req->setMethod(HTTP_REQUEST_METHOD_POST);
$req->addHeader('User-Agent', $ua);
$req->addHeader('Referer', 'http://gdataonline.com/seekhash.php');
$req->addPostData('hash', $str);
if (!PEAR::isError($req->sendRequest()))
{
$data = $req->getResponseBody();
}
if (preg_match('!<td width="35%"><b>(.*?)</b></td>!', $data, $m))
{
return trim($m[1], '?');
}
}
/* Start processing the request */
$clean = array();
$url = array();
$xml = array();
/* Ensure the hash is exactly 32 alpha-numeric characters */
if (strlen($_GET['hash']) == 32 && ctype_alnum($_GET['hash']))
{
$clean['hash'] = $_GET['hash'];
}
else
{
$xml['error'] = escape_xml('The string provided is not a true MD5 hash. Please try again.');
}
/* Perform the MD5 hash lookup */
if (isset($clean['hash']))
{
$url['hash'] = urlencode($clean['hash']);
$string = NULL;
/* Iterate through the MD5 stores to find a value for the hash */
foreach ($md5_stores as $store)
{
$f = "md5_{$store}";
if (($string = $f($url['hash'])))
{
break;
}
}
if (strlen($string) > 0 && ctype_print($string))
{
$clean['string'] = $string;
}
else
{
$xml['error'] = escape_xml('No value in MD5 database for this hash.');
}
}
/* Prepare data for output */
if (isset($clean['hash']))
{
$xml['hash'] = escape_xml($clean['hash']);
}
if (isset($clean['string']))
{
$xml['string'] = escape_xml($clean['string']);
}
/* Set content type to text/xml for output */
header('Content-type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
?>
<md5lookup>
<?php if (isset($xml['error'])): ?>
<error><?php echo $xml['error']; ?></error>
<?php else: ?>
<hash><?php echo $xml['hash']; ?></hash>
<string><?php echo $xml['string']; ?></string>
<?php endif; ?>
</md5lookup>
thanks in advance for anyone that can help.



Reply With Quote
Bookmarks