A server side script (PHP) is used to calculate the MD5 hash of a string. If the Request Method is selected as 'Ajax' and if the browser supports Ajax, then Ajax is used; else normal form submission occurs. It is an example of a Cross Browser script with backward compatibility.
<?php
if( $_POST [ 'ajaxreq' ] == 1 ){
echo getString ( $_POST [ 'str' ], 1 );
exit;
}
function getString ( $str , $method ){
return "<table border='1' width='100%'><tr><td><b>String : </b></td><td> $str </td></tr><tr><td><b>MD5 Hash : </b></td><td>" . md5 ( $str ) . "</td></tr><tr><td><b>Request : </b></td><td>" . ( $method ? 'Ajax Request' : 'Normal Request' ) . "</td></tr></table>" ;
}
?>
<html>
<head>
<title>Simple Ajax MD5 Example</title>
<head>
<script type="text/javascript">
<!--
function ajaxPost(frm){
var req = false;
var self = this;
if(window.XMLHttpRequest) {
self.req = new XMLHttpRequest();
}else{
try{
self.req = new ActiveXObject("MSXML2.XMLHTTP");
}catch(e){
try {
self.req = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){}
}
}
if(!self.req || frm.ajaxreq[1].checked)return true;
else{
self.req.open("POST", frm.action, true);
self.req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
self.req.onreadystatechange = function() {
if (self.req.readyState == 4) {
update(self.req.responseText);
}
}
self.req.send(getQueryString());
return false;
}
}
function getQueryString() {
return "ajaxreq=1&str=" + escape(document.forms[0].str.value);
}
function update(str){
document.getElementById("result").innerHTML = str;
}
//-->
</script>
</head>
<script language="Javascript">
</script>
<style type="text/css">
body,table,div{font:normal 11px Verdana, Arial,sans-serif;}
.frmTable{border:1px #333 solid;background:#F9F9F9;width:330px;text-align:justify;}
</style>
</head>
<body>
<table style="width:100%;height:100%;">
<tr><td>
<center>
<form method="post" onsubmit="return ajaxPost(this);" action="ajax-test.php">
<table class="frmTable" border="1" cellpadding="3">
<tr><td colspan="2">Enter a string below to get its MD5 hash. If Request Method is selected as 'Ajax' and if the browser supports Ajax, then Ajax is used; else normal form submission occurs.</td></tr>
<tr><td><u><b>Enter String:</b></u></td><td><input name="str" value="<?php echo $_POST [ 'str' ]; ?> " type="text"> <input value="Go" type="submit"></td></tr>
<tr><td><u><b>Request Method</b></u></td><td><input id="ajax" <?php if( $_POST [ 'ajaxreq' ] != 0 )echo 'checked' ; ?> type="radio" value="1" name="ajaxreq"/><label for="ajax">Ajax </label> <input id="normal" <?php if( $_POST [ 'ajaxreq' ] == 0 )echo 'checked' ; ?> type="radio" value="0" name="ajaxreq"/><label for="normal">Normal</label></td></tr>
<tr><td colspan="2"><div id="result"><?php if(isset( $_POST [ 'str' ]))echo getString ( $_POST [ 'str' ], 0 ); ?> </div></td></tr>
</table>
</form></center>
</td></tr></table>
</body>
</html>
A damaged image generator (class) for validating text.
CAPTCHA - Completely Automated Public Turing test to tell Computers and Humans Apart Categories : PHP , PHP Classes , Security , GD image library , Security Function to generate readable/remeberable random password Categories : PHP , Security , Security Miguel Categories : AJAX , AJAX Zephyr: AJAX Based Framework for PHP5 Developers Categories : PHP , AJAX , Frameworks , Java Script , Web Applications IPhider Obscure Any URL Anonymity connection lores obfuscation corporate survival. Categories : PHP , Algorithms , Security , URLs A PHP function to encrypt and decrypt a number or string or a combination of the two. Categories : PHP , Encryption , Security Simple AJAX (Jquery) Star Rating System Categories : PHP , AJAX javascript cookie settings Categories : PHP , C++ , AJAX Encoding data using PGP via PHP's proc_* functions Categories : Cryptography , Security , Email , PHP , PGP Why it is not possible to preset a value in a file upload field Categories : HTML , Security , Filesystem , Beginner Guides send_mail function to defeat Header Injection Hacking/Spamming Categories : PHP , Email , Form Processing , Security JSON File Upload Categories : PHP , AJAX , Filesystem Password using php, Javascript, and html form Categories : Security , PHP , Authentication , Java Script IPTables Bandwidth statics Categories : PHP , Security , Network Creates a CAPTCHA image in PHP, which displays 5 numbers stored in a session. Categories : PHP , GD image library , Form Processing , Security