Validating an installation / combining with javascript (1 Viewer)

ajetrumpet

Banned
Local time
Today, 02:50
Joined
Jun 22, 2007
Messages
5,638
all,

I am trying to validate an installation of my product through visual basic. The visual basic code needs to read a validation string in a text box on my web page. Where PHP and JS come is that I have to use them in combination to get the value into the webpage textbox so visual basic can read it. Here is the code I am using:
PHP:
<?php

//If the key is blank, go on to the HTML section
if (! $_POST["key"]) {
	//DO NOTHING
					 }
else
{

$validation = "false";

$logfile = "validation.txt";

//Read file for creating final report
$handle = fopen($logfile, "r");

//If there is no information in the log, display a message and exit
if (filesize($logfile) < 1) {
	$validation = "false";
	fclose ($handle); }
	
//Otherwise, print the report!
else {

$log = fread($handle, filesize($logfile));
fclose ($handle);

// Seperate each logline
$log = explode("|", trim($log)); 

// Seperate each part in each logline
for ($i = 0; $i < count($log); $i++) {
	if ($log[$i] = $_POST["key"])	 {
		$validation = "true"; }
									 }
									 
	 }

if ($validation == "false") {
    
	$handle = @fopen("Validation.txt", "a");
    fputs($handle, $_POST["key"] . "|");
    fclose ($handle);
	
							}
	
}

?>

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Validation Log</title>

<script type="text/javascript">

function CheckValidation() {

	var Val = "<?php echo $validation ?>";
	
		ie.document.getElementById("Confirm").value = Val;
		
}

</script>
</head>

<body>

<form action="" method="post" name="frm" onsubmit="CheckValidation()">
  
    <center><br />
      Enter Your Product Key:<br />
        <input type="text" id="key" name="key" /><br />
        <input type="text" id="Confirm" name="Confirm" />
    </center>
  <p>
    <label>
    <center><input type="submit" id="valcheck" value="Validate" /></center>
    </label>
</p>
</form>

</body>
</html>
As you can probably tell, this code reads a txt file log to check and see if the product key has already been entered, and if it IS there, program operation will be invalid and will shut down because visual basic will read the value I give the text box. The problem I have right now is that my value is not being populated in the box via the JS function.

Is that because the form is submitting BEFORE the code page runs from the top again? I think I'm right in saying that all PHP code runs before any JS, but if I am wrong I'd like to take some redirection from an expert here. Can anyone help me here? Thanks! (I know this might be a bit advanced, but I thought I'd take my chances anyway)
 

Users who are viewing this thread

Top Bottom