我最近更改了我的虚拟主机,不幸的是管理员已禁用了file_get_content和其他一些功能。替代file_get_content(php://输入)
该脚本的目的是直接从设备获取iOS设备的信息。之前,我就是用这个代码可以这样做:
$content = file_get_contents('php://input');
file_put_contents("data.txt", $content);
,结果是这样的(在data.txt中)
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IMEI</key>
<string>01 257233 621346 0</string>
<key>PRODUCT</key>
<string>iPhone2,1</string>
<key>SERIAL</key>
<string>5K1124GHEDG</string>
<key>UDID</key>
<string>07cc825055gftr4edsa3f06d0373376a7664a66a</string>
<key>VERSION</key>
<string>10B329</string>
</dict>
</plist>
由于卷曲功能,我的服务器上启用了,我想这代码以某种不同的方式,但没有奏效。 data.txt因此被清空!
$ch = curl_init();
$timeout = 0;
curl_setopt ($ch, CURLOPT_URL, "php://input");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$contents = curl_exec($ch);
curl_close($ch);
file_put_contents("data.txt", $contents);
更新:
让我解释一下它是如何工作的。我们将用户导向存储在我们服务器上的配置文件(例如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>
该配置文件运行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())));
?>
P.S.
我只需要
<dict></dict>
还有一个curl选项来设置目标文件。 – Charles
curl对php的流不了解。它期望一个合适的网址,并且会正确地抱怨'php'不是一个已知的协议。 –
@MarcB:那你的意思是我不能通过Curt方法获取数据? – PersianHero