Jump to content

Archived

This topic is now archived and is closed to further replies.

0riole

User Authentication

Recommended Posts

Hi,

 

I'm useing the following script to force users to authenticate by including the below script, and I keep getting erors in line 9, but I don't see any, may be just lack of experence :(

 

 

login.php

<?include"vars.php";?>
<?php
 function authenticate() {
  Header("WWW-Authenticate: Basic realm=\"secure login\"");
  echo "Authentication Failed!";
  exit();
 }
 if(!isset($PHP_AUTH_USER)) {h
   authenticate();
   echo "Authorization Failed\n";
   exit;
 } else {
   $checkLogin = "SELECT ID FROM $userTable WHERE
$userField='$PHP_AUTH_USER' AND
$passField='$PHP_AUTH_PW'";
   $db = mysql_pconnect($dbHost, $dbUser, $dbPass);
   mysql_select_db($dbName, $db);
   $result = mysql_query($checkLogin, $db);
   $numrows = mysql_num_rows($result);
   $myrow = mysql_fetch_array($result);
   if ($numrows == 0) {
     authenticate();
   } else {
     setcookie("UserID", $myrow["ID"]);
     $UserID = $myrow["ID"];
   }
 }
?>

 

And here is my vars.php

 

<?
$dbHost = "localhost";
$dbUser = "AdminUser";
$dbPass = "Password";
$dbName = "dbname";
$userTable = "Users";
$userField = "Username";
$passField = "Password";
?>

 

Thanks in advance,

Chris

 

 

Share this post


Link to post
Share on other sites

×

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.