Use PHP to modify the text / heiyeluren to modify the text / heiyeluren today to make a password modification of a PHP web shell program, and our password and program are in the same file, how to do seamless modification, and does not affect The program is executed normally. The format of the configuration file of my program is similar to the following form: / * ================= Configuration option ================= === * /// Log in the user and password, please modify it to your own username and password $ manage [""] = "root"; $ management ["pass" = "123"; // This file is currently Name, please fill in it correctly, otherwise the relevant operation may be invalid $ manage [""] = "./ps101.php";/*================= 配置 结 = = ==================== How do I extract $ manage ['user'] = '' root '' to modify the work, because the file is relatively large, the code Many, the configuration file is in the head section of the program, first think of a basic idea is: use file () traversing the entire file, then find the string of the value of an array is: $ manage ["]" = "root "; Then, use ExPload () to split $ management [" = ", put it in two arrands and then replace the second value to replace the last value after the end of the last The string is rewriting to the file .... But the code is very difficult, and the online is a master, giving such a code: $ lines = file ("config.php"); $ count = sizeof ($ lines); for ($ I = 0; $ I ) {$ TMP = EXPLODE ($ LINES [$ I], '='; if ($ TMP == Null || SizeOf ($ TMP)! = 2 ) Continue; IF (TRIM ($ TMP [0]) == '$ management ["User"]') {$ LINES [$ I] = $ TMP [0]. "=". $ Manage ["user"] Break;}} $ Str = IMPLODE ($ LINES, "/ R / N"); then write $ STR to the file is indeed, according to my idea, the code should be like this, but I will go to execute Not good. How is it half? I have been thinking about half a day, I can do it through regular expressions. Therefore, in consideration of $ management ['' User ''], there is not much time in the program, and may be able to modify it by regular replacement.
Then the basic ideas come out, read all the program code into a variable, and then replace the corresponding content in this string, the code lists: // Open file $ fp = fopen ($ management ["file "], 'r'); // read the file into $ configfile $ configfile = FREAD ($ FP, FileSize); Fclose ($ fp); // Replace $ Configfile = preg_replace / [/ [/ "user /" /] / s * / = / s * [/ "']. *? [/"'] / is "," / $ manage [/ "USER /"] = / "$ user_name /", $ configfile); $ configfile = preg_replace ("/ [$] management / [/" pass / "/] / s * / = / s * [/" ' ]. *? [/ "'] / IS", "/ $ management [/" pass / "] = /" $ user_pass / "", $ configfile); // Retrieve the file back to the original place $ fp = Fopen ($ management ["file"], 'w'); FWRITE ($ FP, TRIM ($ configfile)); fclose ($ fp); so I trial, I can really ~~~~ Written 2004-12 -24 02:00 I wish you all a Merry Christmas!