PHP writes data to form a shell file and removes ^ M

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.