文件获取内容的替代方案(php://input)

文件获取内容的替代方案(php://input),php,ios,curl,file-get-contents,udid,Php,Ios,Curl,File Get Contents,Udid,我最近更改了我的web主机,不幸的是管理员禁用了文件获取内容和一些其他功能 此脚本的目的是直接从设备获取iOS设备的信息。在此之前,我使用此代码执行此操作: $content = file_get_contents('php://input'); file_put_contents("data.txt", $content); 结果是这样的(在data.txt中) 更新: 让我解释一下它是如何工作的。我们将用户引导到存储在服务器上的配置文件(例如device.mobilecon

我最近更改了我的web主机,不幸的是管理员禁用了文件获取内容和一些其他功能

此脚本的目的是直接从设备获取iOS设备的信息。在此之前,我使用此代码执行此操作:

    $content = file_get_contents('php://input');
    file_put_contents("data.txt", $content);
结果是这样的(在data.txt中)

更新:

让我解释一下它是如何工作的。我们将用户引导到存储在服务器上的配置文件(例如device.mobileconfig)。一旦用户点击它,他们就会被要求安装它。其内容是:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>PayloadContent</key>
     <dict>
        <key>URL</key>
        <string>http://mywebsite.com/get.php</string>
        <key>DeviceAttributes</key>
            <array>
                <string>UDID</string>
                <string>VERSION</string>
                <string>PRODUCT</string>
                <string>SERIAL</string>
            </array>
    </dict>
    <key>PayloadDescription</key>
    <string>Install to get device info</string>
    <key>PayloadDisplayName</key>
    <string>UDID Finder</string>
    <key>PayloadIdentifier</key>
    <string>com.myud.ir</string>
    <key>PayloadOrganization</key>
    <string>MyUD.ir</string>
    <key>PayloadRemovalDisallowed</key>
    <false/>
    <key>PayloadType</key>
    <string>Profile Service</string>
    <key>PayloadUUID</key>
    <string>57A223FD-F675-90B1-8F43-22D3FC3BC181</string>
    <key>PayloadVersion</key>
    <integer>1</integer>
</dict>
</plist>

付费内容
统一资源定位地址
http://mywebsite.com/get.php
设备属性
乌迪德
版本
产品
电视连续剧
有效负载描述
安装以获取设备信息
PayloadDisplayName
UDID查找器
有效载荷标识符
com.myud.ir
付费组织
缪德·伊尔
不允许付费删除
有效载荷类型
档案服务
PayloadUUID
57A223FD-F675-90B1-8F43-22D3FC3BC181
付费版本
1.
配置文件运行get.php从设备获取数据。我试过克里斯蒂安的,但没用。我可能在某些地方弄错了。get.php是:

<?php
    $xml = new SimpleXMLElement('<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"/>');
    $dict = $xml->addChild('dict');
    foreach ($_POST as $item => $value) {
        $dict->addChild('string', $item);
        $dict->addChild('key', $value);
    }
    file_put_contents("data.txt", trim(str_replace('<?xml version="1.0"?>', '', $xml->asXML())));
?>

附言

我只需要这些数据

<dict></dict>

假设
php://input
是一个只读流,允许您从请求体读取原始数据,您可以通过获取
$\u POST
数据,然后使用php的
SimpleXMLElement
类创建xml文档,然后将其写入
data.txt
来解决此问题。 您可以通过以下方式继续:

$xml = new SimpleXMLElement('<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"/>');
$dict = $xml->addChild('dict');
foreach ($_POST as $item => $value) {
    $dict->addChild('string', $item);
    $dict->addChild('key', $value);
}
file_put_contents("data.txt", trim(str_replace('<?xml version="1.0"?>', '', $xml->asXML())));

非常感谢你,克里斯蒂安。成功了

我还发现了另一种方法,那就是PEAR php组件,它提供了许多函数,这些函数对于那些像我一样苦苦挣扎的人来说是主要php函数的替代品

例如,在我的例子中,我将file_get_content函数上传到同一个文件夹,并将其包含在get.php中

而不是

 $content = file_get_contents('php://input');
 file_put_contents("data.txt", $content);
我现在正在使用

require_once 'file_get_contents.php';
$content = php_compat_file_get_contents('php://input');
file_put_contents("data.txt", $content);

还有一个curl选项用于设置目标文件。curl不知道php的流。它需要一个正确的url,并且会正确地抱怨
php
不是一个已知的协议。@MarcB:那么你的意思是我不能通过Curt方法获取数据?不。你需要更改发送这些数据到脚本的内容,以便它使用正确的
key=value
POST提交,这样你就可以像往常一样从$\u POST获取数据。或更改为没有荒谬锁定的Web主机。
readfile()
可用吗?无效。请看我的第一篇文章。我添加了更多解释您使用$\u POST将数据传递到php脚本?或者你得到多少?我什么都不做。一旦用户点击“install”,iOS就会与get.php建立连接,并通过$\u POST方法发送我们在概要文件中定义的请求信息(在我们的示例中是:UDUD、版本、产品、序列)。我给你们录了一段关于这个过程的短片。这意味着IOS以不同的方式进行操作,我的意思是尝试将一些post数据传递给脚本,然后您将确认它是否正常工作,您是否尝试更改post以获取?”php://input“允许您从请求中读取原始数据,而不是依赖$u POST,如果请求使用某种特殊格式,则$u POST将为空或无效。因此,必须使用“php://input“因为首先,我们请求一些数据,iOS会回复我们请求数据的结果
$f = fopen('php://input','r');
$out = fopen('data.txt','w');
$body = "";
while( $line = fgets( $f ) ) {
  $body .= $line;
}
fwrite($out, $body);
fclose($f);
fclose($out);
 $content = file_get_contents('php://input');
 file_put_contents("data.txt", $content);
require_once 'file_get_contents.php';
$content = php_compat_file_get_contents('php://input');
file_put_contents("data.txt", $content);