By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,348 Members | 1,397 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,348 IT Pros & Developers. It's quick & easy.

PHP with Javascript authentication

P: 7
I have PHP code that reads a database and displays data.
The display has a edit button that calls a javascript function to
ask for username and password.

I can get the username and password fine and close the login window
fine also.

I want the code to redisplay the PHP differently if the login was
successful. I display the data via a function with an argument
that determines what to display.

Feb 24 '08 #1
Share this Question
Share on Google+
2 Replies

Expert 2.5K+
P: 4,258
We cannot guess what you are doing. Show the code you have developed so far and we will have a look.

And please show that code within the appropriate code tags!

Feb 24 '08 #2

P: 7
This is the main file/routine index.php:


/* Main Screen for Admin purposes.
Call the display in read mode (false)

include_once "adminDisplay.php";


This is the portion of adminDisplay through the creation of the edit button:

function adminDisplay ($writeFlag)

// Query the database for the unconfirmed (code = 0)

// Log in to the database

// 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;
echo <<<END

<!-- Start the page -->


// <!-- Options - Edit or Dump -->

if ($writeFlag == "false"){

echo <<<END

<script language='JavaScript' src='login.js'>

<input type='button' value='Edit Database' onClick=login()>
<a href="printexcel.html">"Dump Database" </a>


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 = ("", "EditLogin", "width=20,height=600,scrollbars=yes,resizable=yes, toolbar=no,location=no,directories=no,status=no,me nubar=no,copyhistory=no");


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">');


function getvalu ()
pValue = loginWin.document.logform.password.value;
uValue = loginWin.document.logform.username.value;

if ((pValue == "admin") && (uValue == "aUser")) {
alert (loginWin.document.logform.password.value);
win = top;
win.opener = top;
win.close ();
return true;


Thanks very much!
Feb 25 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.