hi there i am making an application in which i have a drop down menu which onchange passes a value(this.valu e) to a js function which gets the value and
calls an ajax routine and passes that value to a php page and then takes back the response ,i have done it all but now i was trying to encrypt the information or the string or the value that is passed through the drop down menu and concatinated with the url and passed to that page and then on that page it would call the js function in php and pass that encoded string to an another decoding Javascript function and takes back the decoded string then run the query for the desired values and then response back but i am not doing it right i am pasting only the relevent js and php code here ,thanks for any help in advance.
function Pupu(val) is called onchange and passes the value to the getflds.php page,and function xor_str(url) id the encoding function that encodes the string
MAIN PAGE.PHP
[code=javascript]
function xor_str(url){
//var to_enc = document.forms['the_form'].elements["str"].value;
var to_enc = url;
//var xor_key=documen t.forms['the_form'].elements.xor_k ey.value
var xor_key=6;
var the_res="";//the result will be here
for(i=0;i<to_en c.length;++i){
the_res+=String .fromCharCode(x or_key^to_enc.c harCodeAt(i));
}
//document.forms['the_form'].elements.res.v alue=the_res;
return the_res;
}
function Pupu(val){
if(val!="" && val!="none"){
var fobj=document.f orms['Selfrm'];
var valar=val.split ("|");
var cat_id=valar[0];
var prd_id=valar[1];
var rows=valar[2];
//alert(prd_id);
var prd_name=fobj.e lements['prod'+rows].options[fobj.elements['prod'+rows].selectedIndex].text;
prd_name=stripp er(prd_name);
var url="getflds.ph p?";
var cnct_str="cat_i d="+cat_id+"&pr d_id="+prd_id+" &prd_name="+prd _name+"&rows="+ rows;
var dec_str=xor_str (cnct_str);
alert(dec_str);
var enc_str=decrypt _str(dec_str);
alert(enc_str);
return;
url=url+"str="+ dec_str;
//alert(url);
//return;
xmlHttp=GetXmlH ttpObject();
if(xmlHttp==nul l){
alert("Please Upgrade your browser to continue");
}else{
xmlHttp.onready statechange=sta teFlds;
xmlHttp.open("G ET",url,true) ;
xmlHttp.send(nu ll);
}
}
}
function stateFlds(){
if(xmlHttp.read yState==4){
if(xmlHttp.stat us==200){
alert(xmlHttp.r esponseText);
//var a=xmlHttp.respo nseText;
//var pipe=a.split("^ ");
//var tab=pipe[0];
//var rows=pipe[1];
//alert(tab);
//document.getEle mentById('specs '+rows).innerHT ML=tab;
}
}
}
[/code]
PAGE:GETFLDS.PH P
[CODE=php]
<?
$str=$_GET['str'];
echo $str;
echo "<script type='text/javascript' language='javas cript'>decrypt_ str(".$str.");</script>";
?>
<script type="text/javascript" language="javas cript">
function decrypt_str(){
alert("hi");
var to_dec=<?php echo $str;?>;
var dec_str;
document.forms['the_form'].elements.dec_r es.value="";
var xor_key=6;
for(i=0;i<to_de c.length;i++){
dec_str+=String .fromCharCode(x or_key^to_dec.c harCodeAt(i));
}
document.write( dec_str);
}
</script>
[/CODE]
REGARDS,
OMER ASLAM
calls an ajax routine and passes that value to a php page and then takes back the response ,i have done it all but now i was trying to encrypt the information or the string or the value that is passed through the drop down menu and concatinated with the url and passed to that page and then on that page it would call the js function in php and pass that encoded string to an another decoding Javascript function and takes back the decoded string then run the query for the desired values and then response back but i am not doing it right i am pasting only the relevent js and php code here ,thanks for any help in advance.
function Pupu(val) is called onchange and passes the value to the getflds.php page,and function xor_str(url) id the encoding function that encodes the string
MAIN PAGE.PHP
[code=javascript]
function xor_str(url){
//var to_enc = document.forms['the_form'].elements["str"].value;
var to_enc = url;
//var xor_key=documen t.forms['the_form'].elements.xor_k ey.value
var xor_key=6;
var the_res="";//the result will be here
for(i=0;i<to_en c.length;++i){
the_res+=String .fromCharCode(x or_key^to_enc.c harCodeAt(i));
}
//document.forms['the_form'].elements.res.v alue=the_res;
return the_res;
}
function Pupu(val){
if(val!="" && val!="none"){
var fobj=document.f orms['Selfrm'];
var valar=val.split ("|");
var cat_id=valar[0];
var prd_id=valar[1];
var rows=valar[2];
//alert(prd_id);
var prd_name=fobj.e lements['prod'+rows].options[fobj.elements['prod'+rows].selectedIndex].text;
prd_name=stripp er(prd_name);
var url="getflds.ph p?";
var cnct_str="cat_i d="+cat_id+"&pr d_id="+prd_id+" &prd_name="+prd _name+"&rows="+ rows;
var dec_str=xor_str (cnct_str);
alert(dec_str);
var enc_str=decrypt _str(dec_str);
alert(enc_str);
return;
url=url+"str="+ dec_str;
//alert(url);
//return;
xmlHttp=GetXmlH ttpObject();
if(xmlHttp==nul l){
alert("Please Upgrade your browser to continue");
}else{
xmlHttp.onready statechange=sta teFlds;
xmlHttp.open("G ET",url,true) ;
xmlHttp.send(nu ll);
}
}
}
function stateFlds(){
if(xmlHttp.read yState==4){
if(xmlHttp.stat us==200){
alert(xmlHttp.r esponseText);
//var a=xmlHttp.respo nseText;
//var pipe=a.split("^ ");
//var tab=pipe[0];
//var rows=pipe[1];
//alert(tab);
//document.getEle mentById('specs '+rows).innerHT ML=tab;
}
}
}
[/code]
PAGE:GETFLDS.PH P
[CODE=php]
<?
$str=$_GET['str'];
echo $str;
echo "<script type='text/javascript' language='javas cript'>decrypt_ str(".$str.");</script>";
?>
<script type="text/javascript" language="javas cript">
function decrypt_str(){
alert("hi");
var to_dec=<?php echo $str;?>;
var dec_str;
document.forms['the_form'].elements.dec_r es.value="";
var xor_key=6;
for(i=0;i<to_de c.length;i++){
dec_str+=String .fromCharCode(x or_key^to_dec.c harCodeAt(i));
}
document.write( dec_str);
}
</script>
[/CODE]
REGARDS,
OMER ASLAM
Comment