PHP writes a file to form a shell file. remove the ^ MPHP code: $ file_namesrv1_sysnetwork.cfg; $ sysnetwork_str & quot ;#! Binshnr & quot; if ($ _ REQUEST [mgt_ip] & amp; $ _ REQUEST [mgt_netmask]) PHP writes a file to form a shell file, removing ^ M
PHP code:
$ File_name = '/srv/cfg/sysnetwork. cfg ';
$ Sysnetwork_str = "#! /Bin/sh \ n \ r ";
If ($ _ REQUEST ['mgt _ IP'] & $ _ REQUEST ['mgt _ netmask']) {
$ Sysnetwork_str. = '/sbin/ifconfig mgt '. $ _ REQUEST ['mgt _ IP']. 'netmask '. $ _ REQUEST ['mgt _ netmask']. "\ n \ r ";
}
If ($ _ REQUEST ['ext _ IP'] & $ _ REQUEST ['ext _ netmask ']) {
$ Sysnetwork_str. = '/sbin/ifconfig ext '. $ _ REQUEST ['ext _ IP']. 'netmask '. $ _ REQUEST ['ext _ netmask']. "\ n \ r ";
}
If ($ _ REQUEST ['gateway']) {
$ Sysnetwork_str. = '/sbin/route add default gw'. $ _ REQUEST ['gateway'];
}
$ Write_rs = file_put_contents ($ file_name, $ sysnetwork_str );
\ N \ r of the newline user
The file is as follows:
#! /Bin/sh
^ M/sbin/ifconfig mgt 192.168.2.45 netmask 255.255.255.0
^ M/sbin/ifconfig ext 192.168.2.99 netmask 255.255.255.0
^ M/sbin/route add default gw 192.168.11.1
The result shell cannot be executed. ^ M is found to be missing,
How can this problem be solved?
------ Solution --------------------
Historical problems
Use the standard line break in the server system. you can use the constant PHP_EOL.