/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Need help to add PHP code to display warning on page

Can someone help this newbie with something that appears (to me) to be simple?

I have a page that displays nothing but an “enter password” form which requires the user to enter the default password to gain access to the page. The PHP code in this page checks to see if a certain file exists which contains the password. If the file does not exist, the “password.php” file is created and the following is added to the newly created file:

[code=php]<?php $pwrd = “sdf4256df56sdf56df56f6sf”?>[/code]

The line above is the md5 default password. Basically, if the user is using this page for the first time, he would enter the default password and the password file would be created. Once the user has entered the correct default password, the user then has access to the page.

The reason I am posting here is because I want to add some simple code that will check to see if the “password.php” file exists and if it contains the md5 default password. If it does, I want a warning to be displayed (where ever I choose to place it on the page) which tells the user he needs to change the default password.

Here is the mock up, I just don’t know how to code:

<?php
if file “./password.php” exists and “$pwrd” is equal to “sdf4256df56sdf56df56f6sf”
{
Then display warning “<div>blah, blah</div>”
}
Else do nothing
?>

Any help would be appreciated?

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@SyCoOct 22.2008 — THis should do it. PHP functions are often quite literally named. If you can work out the logic then the coding is the easy part.

[code=php]
$filename='password.php';//if file in same directory otherwise change
include ($filename);
if(file_exists($filename) && $pwrd=="sdf4256df56sdf56df56f6sf") {
echo 'Change your password';
}[/code]


file_exists

include
Copy linkTweet thisAlerts:
@jeffsheadauthorOct 22.2008 — Thanks SyCo! Worked just fine.? I went to

http://us3.php.net/manual/en/function.file-exists.php

and

http://us3.php.net/manual/en/function.file.php

but I just could not put it together.
Copy linkTweet thisAlerts:
@SyCoOct 22.2008 — file() might seem like the obvious choice as it would make an array out of the lines which you could then use strstr() to look at the password with, but include() in this case is nice and simple.

Glad it works for you.
Copy linkTweet thisAlerts:
@ayveghOct 23.2008 — Keep in mind that if the inputted password is not properly escaped/cleaned, a malicious user with knowledge of how the script works could easily inject his own code into the saved file, which would then be executed when the include() is called.

Just one argument why file() would be a better choice, but I personally prefer include() anyways. ?
Copy linkTweet thisAlerts:
@SyCoOct 23.2008 — That's a very good point. Nice security tip.
×

Success!

Help @jeffshead spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...