Jump to content

.htaccess / PHP relationship, interaction


scott_ttocs46

Recommended Posts

Hi All,

 

I manage a high volume website. Currently, there are many unnecessary MYSQL inquiries. It would be much easier to handle updates and changes using CRON. I am certain this is how I want to handle the efficiency problem. I will have compiled HTML pages. I assume .htaccess is the best way to control access to the html pages.

 

However, my issue is authentication. I can manage the .htaccess file. However, I am not sure how to detect who is logged in. The dynamic aspects of the site (PHP pages) will need to be able to detect who is logged in via .htaccess.

 

Any ideas?  ???

 

Also, do you think using .htaccess versus PHP authentication poses a security risk? The only downside I see is the .htaccess won't use salts for the MD5 hashes like my PHP authentication does.

 

Scott

Link to comment
Share on other sites

This looks useful but the Apache/PHP relationship is unclear to me -

 

function authenticate(){
  header("WWW-Authenticate: Basic realm=\"Members\"");
  header('HTTP/1.0 401 Unauthorized');
  echo "Please enter a valid user name and password.";
  exit;
}

for(; 1; authenticate()){
  if (!isset($HTTP_SERVER_VARS['PHP_AUTH_USER'])) continue;
  $user = $HTTP_SERVER_VARS['PHP_AUTH_USER'];
  if(!($authUserLine =
    array_shift(preg_grep("/$user:.*$/",
    file("/home/kloss/html/test/.htpasswd"))))) continue;
  preg_match("/$user:((..).*)$/", $authUserLine, $matches);
  $authPW = $matches[1];
  $salt = $matches[2];
  $submittedPW = crypt($HTTP_SERVER_VARS['PHP_AUTH_PW'], $salt);
  if($submittedPW != $authPW) continue;
  break;
}

 

Found it at http://code.activestate.com/recipes/108479/

 

 

EDIT: Would there be an Apache server variable for the .htaccess username? I.e. $HTTP_SERVER_VARS

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.