Jump to content

Checking if file contains a string.


feverbird
Go to solution Solved by Ch0cu3r,

Recommended Posts

Hi Community! :-) (Sorry for my average english)

I recently started coding in php, till now, i allready have advanced skills in programming with C# and thus, had no problems writing my own script.

 

Still, my script does not really work, i'm trying to check if a file contains a md5(string), but the script never finds the string.

This is the script: (please don't mind any security issues, this is just a test. But if you have any tips and tricks to improve the security, i'd be glad to receive them)

<?php
$webname = $_POST["webname"];
$webcode = $_POST["webcode"];
$webpass = $_POST["webpass"];
if (file_exists("web/". $webname . ".html")) {
$file = file_get_contents("web/". $webname . ".html", "r");

if (strpos(md5($webpass),$file) !== false) {
$usergen = fopen("web/" . $webname . ".html", "w")  or die("Unable to open file!");
fwrite($usergen, $webcode);
fwrite($usergen, "<!--- ". md5($webpass) . "--->");
fclose($usergen);
echo "Generated! You can view your site under /web/" . $webname . ".html";
}
else
{
echo "The file already exists but you entered the wrong Password.<br> Pressing the \"return\" Button will bring you back without loosing the code you entered.";
}
}
else
{
$usergen = fopen("web/" . $webname . ".html", "w")  or die("Unable to open file!");
fwrite($usergen, $webcode);
fwrite($usergen, "<br><!--- ". md5($webpass) . " --->");
fclose($usergen);
echo "Generated! You can view your site under /web/" . $webname . ".html";
}
echo "<FORM><INPUT Type=\"button\" VALUE=\"Back\" onClick=\"history.go(-1);return true;\"></FORM>";
?>

What it does it pretty simple, you enter some html-code that'll be stored in the "webcode" variable, a password, let's say "apple" in "webpass" and the filename is stored in "webname".
On first creation, a html-file is created with the
<!--- md5(apple) --->

at it's end, the HTML Tags are needed to hide the string from any visitors.

If someone wants to edit the File created before, he also enters "apple".
Then the string will be looked up as md5(apple) in the file.
If the strings match, it's true and the changes should be saved.
Whatever i do, though, i'm allways ending up here if i try to edit an existing file:

"The file already exists but you entered the wrong Password.<br> Pressing the \"return\" Button will bring you back without loosing the code you entered.";
As i said, i'm a newbie, i'd appreciate any tips and help.

Thank you in advance!

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.