开发者

PHP Form - Fetch file and download using CURL

开发者 https://www.devze.com 2023-01-31 12:56 出处:网络
Now Delicious is closing down, I tried to make a PHP form for a few friends to use to download there bookmarks:

Now Delicious is closing down, I tried to make a PHP form for a few friends to use to download there bookmarks:

Vising this url: https://api.del.icio.us/v1/posts/all

You get prompted for a username and password then presented with XML, I want to automate the download of the XML returned.

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);

        $username = $_POST['username'];
        $password = $_POST['password'];
        $url = "https://api.del.icio.us/v1/posts/all"

?>
<form ACTION="<?php echo $PHP_SELF;?>" name="bookmarkform" METHOD="POST" align="center">
    <table>
        <tr>
            <td>
                <label>Username</label>
            </td>
            <td>
                <input NAME="username" tabindex="1">
            </td>
        </tr>
        <tr>
            <td>
                <label>Password</label>
            </td>
            <td>
                <input NAME="password" tabindex="2">
            </td>
        </tr>
        <tr>
            <td>
                &nbsp;
            </td>开发者_JS百科
            <td>
                <input TYPE="submit" tabindex="3" value="Submit!">
            </td>
        </tr>
    </table>
</form>

Im missing something here but cant see what? Any help appreciated : )


Well, I'm not familiar with Delicious API, but my first suggestions is not to use undefined variables:

    <?php
    $username = $_POST['username'];
    $password = $_POST['password'];
    $url = "https://api.del.icio.us/v1/posts/all"
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    $output = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);

    ?>
0

精彩评论

暂无评论...
验证码 换一张
取 消