PDA

View Full Version : Word comparing



mahan1559
سه شنبه 18 مرداد 1384, 18:41 عصر
salam, man daram ye page misazam ke user betoone passwordesho taghir bede. albate password rooye ye file txt neveshte shode.

<!-- FIRST FILE -->

<html>
<body>
<h1>Changing password</h1>
<form action="scripts/changePassB.php" method="post">Old password: <br>
<input type="text" name="oldPass" size="30"> <br>New password: <br>
<input type="text" name="newPass1" size="30"> <br>Confirm new password: <br>
<input type="text" name="newPass2" size="30"> <br><br>
<input type="submit" value="Change password">
</form>
</body>
</html>


<!-- SECOND FILE -->

<?php

$oldPass = @$_POST["oldPass"];
$newPass1 = @$_POST["newPass1"];
$newPass2 = @$_POST["newPass2"];
$filePointer = fopen("./password.txt","r");
$word = fgets($filePointer, 4096);

if($oldPass !== $word){
fclose($filePointer);
header('Location: ./changePassA');
exit();

} else {
if ($newPass1 !== $newPass2){
fclose($filePointer);
header('Location: ./changePassA');
exit();
} else{
// Set the new password to be written to the file
$values = "$newPass1\r";
// Open the file for truncated writing
//******** ERROR **********//
$fp = fopen("../password.txt", "w+") or die("Couldn't open password.txt for writing!");
$numBytes = fwrite($fp, $values) or die("Couldn't write the new password to file!");
fclose($filePointer);
fclose($fp);
header('Location: ./changePassA');
}
}

?>

kesi mitoone ba man komak kone ke in code kar kone.

mamnoon & khosh bashid

tabib_m
سه شنبه 18 مرداد 1384, 21:37 عصر
بهتر بود اینجوری بنویسی :


$oldPass = @$_POST["oldPass"];
$newPass1 = @$_POST["newPass1"];
$newPass2 = @$_POST["newPass2"];
$filePointer = fopen("./password.txt","r");
$word = fgets($filePointer, 4096);

if($oldPass !== $word){
fclose($filePointer);
header('Location: ./changePassA');
exit();

} else {
if ($newPass1 !== $newPass2){
fclose($filePointer);
header('Location: ./changePassA');
exit();
} else{
// Set the new password to be written to the file
$values = "$newPass1\r";
// Open the file for truncated writing
//******** ERROR **********//
$fp = fopen("../password.txt", "w+") or die("Couldn't open password.txt for writing!");
$numBytes = fwrite($fp, $values) or die("Couldn't write the new password to file!");
fclose($filePointer);
fclose($fp);
header('Location: ./changePassA');
}
}

?>


:)