Search code examples
phpioscurlfile-get-contentsudid

Alternative to file_get_content (php://input)


I've recently changed my web hosting and unfortunately the administrator has disabled file_get_content and some other functions.

The aim of this script is to get iOS device's information directly from device. Before, I was using this code to do so:

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

And the result was like this (in 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>

As the Curl function is enabled on my server, I tried this code in some different ways, but didn't work. The data.txt is emptied as a result!

    $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);

UPDATED:

Let me explain how it works. We direct users to a profile which is stored on our server(e.g device.mobileconfig). Once users click on that, they will be asked to install that. Its content is:

<?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>

The profile runs get.php to fetch data from device. I tried Cristian's one but did not work. I probably have a mistake some where. The get.php is:

<?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.

I just need the data between

<dict></dict>

Solution

  • Thank you very much Cristian. it worked.

    I also found another way which is PEAR php Component that provides lots of functions which are alternative to main php functions for those people who are struggling like me!

    for instance, in my case, I uploaded the file_get_content function to the same folder and included that in get.php

    instead of

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

    I'm now using

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