PHP with Javascript authentication

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • igraffman
    New Member
    • Feb 2008
    • 7

    PHP with Javascript authentication

    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.

    Thanks
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    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!

    Ronald

    Comment

    • igraffman
      New Member
      • Feb 2008
      • 7

      #3
      This is the main file/routine index.php:

      <?php

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


      include_once "adminDisplay.p hp";

      adminDisplay("f alse");
      ?>


      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_unc onfirmed = 'SELECT * FROM `classmates` WHERE `confirmed` = \'0\' LIMIT 0, 100';
      $result = mysql_query($qu ery_view_unconf irmed);

      // if error:
      if (!$result) {
      $message = 'Invalid query: ' . mysql_error() . "\n";
      $message .= 'Whole query: ' . $query_view_unc onfirmed;
      die($message);
      }
      echo <<<END

      <!-- Start the page -->
      <html><head>
      <center>

      END;

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

      if ($writeFlag == "false"){

      echo <<<END

      <script language='JavaS cript' src='login.js'>


      </script>
      <input type='button' value='Edit Database' onClick=login() >
      <a href="printexce l.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,heigh t=600,scrollbar s=yes,resizable =yes,toolbar=no ,location=no,di rectories=no,st atus=no,menubar =no,copyhistory =no");

      loginWin.resize To(300,200)

      loginWin.docume nt.write("here" );
      loginWin.docume nt.write('<form name="logform" action="" onSubmit="windo w.opener.getval u()">');
      loginWin.docume nt.write('<labe l>Username</label><br/><input name="username"/><br/>');
      loginWin.docume nt.write('<labe l>Password</label><br/><input name="password" type="password"/><br/>');
      loginWin.docume nt.write('<inpu t type="submit" name="login" value="login">' );
      loginWin.docume nt.write('</form>');

      }



      function getvalu ()
      {
      pValue = loginWin.docume nt.logform.pass word.value;
      uValue = loginWin.docume nt.logform.user name.value;
      loginWin.close( );

      if ((pValue == "admin") && (uValue == "aUser")) {
      alert (loginWin.docum ent.logform.pas sword.value);
      win = top;
      win.opener = top;
      win.close ();
      }
      return true;

      }


      Thanks very much!

      Comment

      Working...