Jump to content

Ask! Bugs from file_get_contents()


nicx

Recommended Posts

Mr.I was create a source view html with file_get_contents() function.But that have a bug,so someone can know my cpanel username and password. Where he can know that? What method he use? My code

<form action="" method="post"><input type="text" name="url" /><input type="submit" value="submit" /></form><?php$file = @file_get_contents($_POST["url"]);echo nl2br(htmlspecialchars($file));?>

Link to comment
Share on other sites

I found that the easiest way to prevent the user from viewing your source code and just seeing html is by making them put in the full url (including http:// or https://) So the following should work and has a validator.

<form action="" method="post">You must place the full url starting with http:// or https://<br />
<input type="text" name="url" value="http://<? echo $_SERVER['SERVER_NAME']; ?>"/>
<input type="submit" value="submit" /></form>
<?php
if (isset($_POST["url"]) && substr($_POST["url"],0,4)==='http')
    {
    $file = @file_get_contents($_POST["url"]);
    echo nl2br(htmlspecialchars($file));
    } else if (isset($_POST["url"])) {
echo "You must have the full url starting with http:// or https://";
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.