Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A php file and .htaccess/.htpasswd 3

Status
Not open for further replies.

tijerina

Vendor
Mar 4, 2003
132
US
Is there a way for me to password protect a php file rather than the entire directory?

I have a php calendar that allows people to schedule appointments. And once they schedule it, there first name will appear on that specific date and time they choose. But the name that is on the calendar is in the date box and is a link. The link is a "viewdetails.php" file. How do I protect this "viewdetails.php" file only.

So if somebody went to my site and wanted to schedule a service, they could see a persons first name and know that the time slot is booked, but if they clicked on that first name, they could see details. This I want to avoid..

What can I do?

Thanks..
 
try putting this on the viewdetails.php page at the top before the <html> tag!!

Code:
<?php 
$auth = 0; 
if (($PHP_AUTH_USER == "username" ) && ($PHP_AUTH_PW == "password" )) $auth = 1; 
if ( $auth != 1 ) { 
    header( "[URL unfurl="true"]WWW-Authenticate:[/URL] Basic realm="Authorization Required!"" ); 
    header( "HTTP/1.0 401 Unauthorized" ); 
    echo 'Authorization Required!'; 
    exit; 
}

hope it helps!


Regards,

Martin

Gaming Help And Info:
 
Just a few corrections to the code:

Use $_SERVER['PHP_AUTH_USER'] and $_SERVER['PHP_AUTH_PW'] in the "if" statement.

In the first HEADER, there are some unsecaped quotes.

Ken
 
Thanks for your help.

It did not work, is there another process I need to complete so this works?

When I click on the name in the calendar (which is a link to the "viewEvent.php" file, where the code is.)
The results are this:

The top of the web page shows this..

$auth = 0; if $_SERVER['PHP_AUTH_USER'] && $SERVER['PHP_AUTH_PW'] $auth = 1; header( " Basic realm="Authorization Required!"" ); header( "HTTP/1.0 401 Unauthorized" ); echo 'Authorization Required!'; exit; }
 
Your file is not being interpreted by PHP. Are you sure it's a PHP file and you have surrounded your code with "<?PHP" and "?>"?

What happens if you type the path to that file into your browser?

Ken
 
MJB3K and kenrbnsn

I thank you both for your help, it WORKED!!!

Stars for you both!!!

Again, thanks a million!!
 
What was the solution to your problem. If someone has a similar problem and finds this thread, a solution would be helpful.

Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top