p2p.wrox.com Forums

Need to download code?

View our list of code downloads.

  Return to Index  

beginning_php thread: Authenticate User PassWord/UserName

Message #1 by "dean powell" <gtrorg@a...> on Fri, 27 Jul 2001 11:50:12
Function difficulties in the variable comparison with database field record

Beginner:Attempting to Authenticate User PassWord/UserName

Can you splot my error?



<TITLE>Retrieving Data from a Database</TITLE>



// Set the pop up window to input Password and UserName

function  authenticate()  {

      Header( "WWW-authenticate: basic  realm=\"Authentication  System\"");

      Header( "HTTP/1.0  401  Unauthorized");

      echo  "You  must  enter  a  valid  login  ID  and  password  to  

access  this  resource\n";



// Set the variables for the database access:

$Host = "localhost";

// Removed variables for security:

$User = "XXXXXXXXX";

$Password = "XXXXXXX";


$TableName = "XXXXXXX";

// Connects to database

$Link = mysql_connect ($Host, $User, $Password);

$Query = "SELECT * FROM users WHERE username='$PHP_AUTH_USER' and 


from $TableName";

$Result = mysql_db_query ($DBName, $Query, $Link);

  if(!isset($PHP_AUTH_USER)  ||  ($SeenBefore ==  1  &&  !strcmp($OldAuth, 

 $PHP_AUTH_USER))  )  {



  else  {

    echo  "Welcome:  $PHP_AUTH_USER<BR>";

    echo  "Old:  $OldAuth";

    echo  "<FORM  ACTION=\"$PHP_SELF\"  METHOD=POST>\n";

    echo  "<INPUT  TYPE=HIDDEN  NAME=\"username\"  VALUE=\"1\">\n";

    echo  "<INPUT  TYPE=HIDDEN  NAME=\"password\"  


    echo  "<INPUT  TYPE=Submit  VALUE=\"Re  Authenticate\">\n";

    echo  "</FORM>\n";


mysql_close ($Link);

print ("</TABLE>\n");




Could someone correct my code I have attempted to sandwich the Authenticate

code from the PHP manual with code to retrieving data from my local MySQL 



  Return to Index