i have written a script that takes the users input from an textarea and puts it in a text file. It also checks if the users piece of text already exists in the text file, in that case it does not write to the file (to prevent duplicate entries). In my code below, the file in question is 'textfile.txt'. Instead of that one i want to edit a file on a SFTP server. I've read something about ssh2_sftp but i didn't understand how to use it. Please help me!
Also, is there any security risk to let people edit a text file on a server using the code below? (except spamming and the file getting ridicously large, as i am using a CAPTCHA for the input form).
Thank you!
<?
$text = $_POST['update'];
$handle = file_get_contents("textfile.txt",NULL);
$text=str_replace(",","",$text);
$text=explode(" ",$text);
$c=0;
foreach($text as $y){
if (stristr($handle,"$text[$c]")) $b[]= 'yes';
else $b[]='no';
$c++;
}
echo $handle;
if (in_array("no",$b)) /*här */if($_POST['Submit']){
$open = fopen("textfile.txt","a+");
$text = $_POST['update'];
fwrite($open, "".$text."\n");
fclose($open);
echo "<br/><br/><br/>".$text." has been saved.";
foreach($file as $text) {
echo $text."<br />";
}
}else{
}
else echo '<br/><br/>Thats already in there.';
?>