Transfer of variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gsashwin
Forum Newbie
Posts: 4
Joined: Thu Nov 18, 2010 12:11 am

Transfer of variables

Post by gsashwin »

I am trying to transfer the variables of the form (username & password )in the html page to the process.php page which are both given below. However I am not able to read those values from the process.php page. Can anyone please let me know what is going wrong here? Thanks in advance and appreciate your help.

HTML Page

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script language="JavaScript" type="text/javascript">
function xor_str()
{
var username_val = document.forms['the_form'].elements["username"].value;
var password_val = document.forms['the_form'].elements["password"].value;
var xor_key='1234';
var username_res="";
var password_res=""
for(i=0;i<username_val.length;++i)
{
username_res+=String.fromCharCode(xor_key^username_val.charCodeAt(i));
}
for(i=0;i<password_val.length;++i)
{
password_res+=String.fromCharCode(xor_key^password_val.charCodeAt(i));
}
// XOR is done

//shifting the username_res to the left by 1 bit
//username_res = username_res << 1;
//shifting the password_res to the left by 1 bit
//password_res = password_res << 1;

//setting the xor'ed and shifted value for submission
document.forms['the_form'].elements["username"].value = username_res;
document.forms['the_form'].elements["password"].value = password_res;
//alert("UserName: " + username_res);
//alert("Password: "+ password_res);
the_form.submit(); // is this step right?


}
</script>
</head>

<body>
<form name="the_form" action="process.php" method="post">
<table>
<tr><td colspan="3">Username:<input type="text" name="username"></td></tr>
<tr><td>Password: <input type="text" name="password"></td><td colspan="2"><input type="button" onClick="xor_str()" value="Submit"></td></tr>
</table>
</form>
</body>s

</html>






Process.php page


<html><body>
<?php
$username = $_POST['username'];
$password = $_POST['password'];

echo "You ordered ". $username . " " . $password . ".<br />";
echo "Thank you ";

?>
</body></html>
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: Transfer of variables

Post by cpetercarter »

If you change the submit button to a normal <input type="submit"> button (ie so that the username/password are submitted in plain text and not obfuscated by your Javascript function) can you then read the $_POST variables?
Post Reply