| re: PHP with Javascript authentication
This is the main file/routine index.php:
<?php
/* Main Screen for Admin purposes.
Call the display in read mode (false)
*/
include_once "adminDisplay.php";
adminDisplay("false");
?>
This is the portion of adminDisplay through the creation of the edit button:
<?php
function adminDisplay ($writeFlag)
{
// Query the database for the unconfirmed (code = 0)
// Log in to the database
require_once("../php/config.php");
// Query for all entries
$query_view_unconfirmed = 'SELECT * FROM `classmates` WHERE `confirmed` = \'0\' LIMIT 0, 100';
$result = mysql_query($query_view_unconfirmed);
// if error:
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query_view_unconfirmed;
die($message);
}
echo <<<END
<!-- Start the page -->
<html><head>
<center>
END;
// <!-- Options - Edit or Dump -->
if ($writeFlag == "false"){
echo <<<END
<script language='JavaScript' src='login.js'>
</script>
<input type='button' value='Edit Database' onClick=login()>
<a href="printexcel.html">"Dump Database" </a>
END;
}
echo <<<END
?>
And finally the jogin.js code. User name and password are not the ones I am going to use!
// This function opens the login window.
var loginWin;
var pValue;
var uValue;
function login ()
{
loginWin = window.open ("", "EditLogin", "width=20,height=600,scrollbars=yes,resizable=yes, toolbar=no,location=no,directories=no,status=no,me nubar=no,copyhistory=no");
loginWin.resizeTo(300,200)
loginWin.document.write("here");
loginWin.document.write('<form name="logform" action="" onSubmit="window.opener.getvalu()">');
loginWin.document.write('<label>Username</label><br/><input name="username"/><br/>');
loginWin.document.write('<label>Password</label><br/><input name="password" type="password"/><br/>');
loginWin.document.write('<input type="submit" name="login" value="login">');
loginWin.document.write('</form>');
}
function getvalu ()
{
pValue = loginWin.document.logform.password.value;
uValue = loginWin.document.logform.username.value;
loginWin.close();
if ((pValue == "admin") && (uValue == "aUser")) {
alert (loginWin.document.logform.password.value);
win = top;
win.opener = top;
win.close ();
}
return true;
}
Thanks very much!
|