/    Sign up×
Community /Pin to ProfileBookmark

php password protection

I have a file called /pPlans_display.php that pulls data based on the id from the database (/pPlans_display.php?id=94)

I have a column in the table where the data resides, but how could i make pPlans_display.php ask for a password if the particular id says it needs to be password protected?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@PierceMooreJul 10.2009 — It is just a quick hash-out, but you are probably going to need something like this:

[code=php]<?php
$get = mysql_query("
SELECT *
FROM tablename
WHERE column
= field
") or die (mysql_error());
$fetch = mysql_fetch_assoc($get);

if(isset($_POST['getfield'])) {
if(strcmp($fetch['protected'],'n') != 0) : ?>
<form action="<?php print $_SERVER['PHP_SELF']; ?>" method="post">
<p><label>Password:<input type="text" name="password" /></label></p>
<p><input type="submit" name="pass_submit" value="Submit" /></p>
</form>
<?php endif;
}

if(isset($_POST['pass_submit'])) {
$pass = $_POST['pass_submit'];
$comp = strcmp($fetch['password'],$pass);
if($comp !== 0) {
// Passwords do not match!
} elseif ($comp === 0) {
// Success! Passwords Match!
}
}
?>[/code]


Check that out and let me know how it goes!


Pierce
×

Success!

Help @CodeNameJeff 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 6.16,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...