PHP 写资料,形成一个shell文件,去掉^M
PHP 写文件,形成一个shell文件,去掉^M
PHP 代码:
$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
形成的文件如下:
#!/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
结果shell不能执行,发现多了^M ,
怎么解决?
------解决方案--------------------
历史问题
用服务器系统下的标准换行符即可,可以用常量PHP_EOL

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The Chinese meaning of request is "request". It is a global variable in PHP and is an array containing "$_POST", "$_GET" and "$_COOKIE". The "$_REQUEST" variable can obtain data and COOKIE information submitted by POST or GET.

How to use the urllib.request.urlopen() function in Python3.x to send a GET request. In network programming, we often need to obtain data from a remote server by sending an HTTP request. In Python, we can use the urllib.request.urlopen() function in the urllib module to send an HTTP request and get the response returned by the server. This article will introduce how to use

The minimal installation version of centos7 does not have the ifconfig command. Currently, centos7 has replaced the ifconfig command with the ip command. ifconfig is a deprecated command in net-tools and was not maintained many years ago. The iproute2 suite provides many commands with enhanced functions, and the ip command is one of them.

1. Create a new file called request.js and import Axios: importaxiosfrom'axios'; 2. Create a function called request and export it: This will create a function called request and export it Set up a new Axios instance with a base URL. To add timeout settings in a wrapped Axios instance, you can pass the timeout option when creating the Axios instance. exportconstrequest=axios.create({baseURL:'https://example.

Request in PHP refers to request. It is a super global variable in PHP. It is used to collect data submitted by HTML forms and parameters in URLs. It can obtain data from GET and POST requests at the same time. Note that $_request is an associative array. , where the keys are the names of the form fields and the values are the values of the form fields. When using the $_request variable, user-entered data should always be validated and filtered to avoid security issues.

The Request object in PHP is an object used to handle HTTP requests sent by the client to the server. Through the Request object, we can obtain the client's request information, such as request method, request header information, request parameters, etc., so as to process and respond to the request. In PHP, you can use global variables such as $_REQUEST, $_GET, $_POST, etc. to obtain requested information, but these variables are not objects, but arrays. In order to process request information more flexibly and conveniently, you can

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

The role and significance of Request in PHP In PHP programming, Request is a mechanism for sending requests to the Web server. It plays a vital role in Web development. Request is mainly used to obtain data sent by the client, such as form submission, GET or POST request, etc. Through Request, the data input by the user can be obtained, and the data can be processed and responded to. This article will introduce the role and significance of Request in PHP and give specific code examples.
