Link to home
Start Free TrialLog in
Avatar of roscoeh23
roscoeh23

asked on

Basic HTTP Authentication

Hi,

I want to password protect a single php page. Can someone tell me how to do this.

Thanks,


R.
Avatar of Mark Gilbert
Mark Gilbert
Flag of United States of America image

You could check for a value from a password field if it's only for one page:



Hope this helps.
<?php 
 
$password = "mypasswordhere";
 
if(isset($_POST['password'])){
if($_POST['password']==$password){
// user is authenticated, show them some stuff:
?>
Display some authenticated stuff here in the page.  
 
<?php 
} else{ 
// display a form for them to login:
 
?>
<form action="post">
<input type="password">
<input name="submit" type="button" value="submit" /></form>
<?php 
}
?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Joe Wu
Joe Wu
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial