php - Edit file on SFTP server -


I wrote a script that takes input from users from a textile and puts it in a text file. That the piece of users present in the text file already exists, in that case it does not write the file (to prevent duplicate entries). In my code, the file in question is 'textfile.txt' instead I want to edit a file on a Sftp server. I've read something about ssh2_sftp, but I did not understand how to use it. Please help me!

Besides, is there a security risk, so that people can edit a text file on the server using the code given below? (Except spamming and the file is getting ridiculously large, because I'm using captcha for input forms).

Thank you!

  & lt;? $ Text = $ _POST ['update']; $ Handle = file_get_contents ("textfile.txt", NULL); $ Text = str_replace (",", "", $ text); $ Text = explosion ("", $ text); $ C = 0; Foreign exchange (text as $ y) {if (stristr ($ handle, "$ text [$ c]")) $ b [] = 'yes'; And $ B [] = 'no'; $ C ++; } Resonance $ handle; If (in_array ("no", $ b)) / * hà * * / if ($ _ POST ['submit']) {$ open = fopen ("textfile.txt", "a +"); $ Text = $ _POST ['update']; Fillit ($ open, "". $ Text. "\ N"); Fclose ($ open); Ebb 
















$ Text "Has been saved."; Foreign currency (file as $ $ $ file) {$ echo $ text "& Lt; br / & gt;"; ? & Gt;

Yes unless you are displaying the contents of the file (since I You see, you're using a echo $ handle; to display this), then someone can submit the prepared HTML to the XSS attack.

You may want to consider input data to help stop them.

Along with this, due to the use of a DOS attack can be launched very easily. File_get_contents on an unknown size file. This can only be reduced by looping through file-line-by-line or setting the range of how long the text the user has presented can be. This attack is using captcha, because most users may be slow by sending text faster, but if file_get_contents () is called without the use of captcha (say, the file's

Edit: I rewrite most of your code snippets for you and add many comments. Hopefully you can pick up some tips and tips from And all the people The Resht can gain a better understanding of programming practices. (I have not tried to run code, but it should work fine. You need to modify it.)


Comments