<?
if(isset($_POST['Submit']))
{
$password=$_POST['newpwd'];
if(!empty($password))
{
$old_file = "password.txt";
chmod($old_file,0777);
$fh = fopen($old_file, 'w') or die("Can't open file");
fwrite($fh,$password);
fclose($fh);
header("location:index.php");
}
else
{
echo "Please enter a valid password!";
}
}
?>
Above code is used to reset the password. I am getting error "Can't open file" when change the password. Also the chmod operation is not working. The file permission is given below:
-rwxr-xr-x 1 root root 4 Mar 5 13:55 password.txt
I have tried unlink to delete the text file, it also failed.
The above code is working when I delete the text file manually, and then set the file permission to 777.
Any help should be appreciated!