Pop up login form at my index.php

Hi…

i have a login page and it is separately in my index.php

now i need my login page become a pop up form when I open my index.php

here is my login.php


<?php
  include 'config.php';

  session_start();

  //if (isset($_SESSION['logged_in'])) {
   //  header('Location:index.php');
  //   die();
 // }

  if (isset($_POST['submit'])) {
    $username=$_POST['username'];
    $password=($_POST['password']);

     $sql = "SELECT username, password FROM pay_login WHERE username='$username' AND password='$password'";
     $rs = $conn2->Execute($sql);

     if($rs==1){
        $_SESSION['logged_in'] = true;
        header("location:index.php");
    }
    else {
    echo "<center>";
    echo "Wrong Username or Password";
    echo "</center>";
    }
  }

$smarty->display('login.tpl');

?>

and here is my index.php


<?php
 session_regenerate_id(true);
/*include 'config.php';

if (!isset($_SESSION['empID'])) {
$sql = "SELECT EMP_ID FROM PERSONAL";
$recPersonal = $conn->Execute($sql);

if (!$recPersonal->BOF) {
    $recPersonal->MoveFirst();
}
session_register('empID');
$_SESSION['empID'] = $recPersonal->fields['EMP_ID'];
}   */
include 'config.php';
$currentEmpID = $_SESSION['empID'];

if (!isset($_SESSION['empID'])) {
$sql = "SELECT EMP_ID, CONCAT(LNAME, ', ' , FNAME, ' ', MI) AS FULLNAME FROM PERSONAL ORDER BY LNAME ASC";
$recPersonal = $conn->Execute($sql);

session_register('empID');
$_SESSION['empID'] = $recPersonal->fields['EMP_ID'];
}

$sql = "SELECT EMP_ID, CONCAT(LNAME, ', ' , FNAME, ' ', MI) AS FULLNAME FROM PERSONAL ORDER BY LNAME ASC";



$recPersonalNav = $conn->GetAll($sql);


$smarty->assign('personalAll', $recPersonalNav);
// ========================================================================================================================

$sql = "SELECT EMP_ID, CONCAT(LNAME, ', ',  FNAME, ' ', MI, '.') AS FULLNAME FROM PERSONAL
         WHERE EMP_ID='$currentEmpID'";

$recPersonalHead = $conn->Execute($sql);
$fullName = $recPersonalHead->fields["FULLNAME"];
$smarty->assign('empid', $currentEmpID);
$smarty->assign('fullname', $fullName);

session_write_close();
 $smarty->display('header.tpl');
 $smarty->display('left.tpl');
$smarty->display('empPayroll.tpl');
 $smarty->display('footer.tpl');
 exit();
?>

and I found a sample pop up code in internet but this pop needs a button befre it was displayed…I want is it will display when i run my index.php

here is the link of sample pop up form
http://www.nigraphic.com/blog/java-script/how-open-new-window-popup-center-screen

Thank you

the Javascript-neutered among us will say thats a bad idea. But, for those that arnt, have your PHP echo out the window.open javascript if the session has not been logged in.

PS: Your query on line 6 of index.php doesnt work.

I did not try, but some told me to used overlay?

But im not familiar on that…

Thank you

:nono: this is not a good sign and a bad idea generally :nono:

Cobbling together bits and pieces of code from “cyberspace” is fraught with danger and likely to lead to problems as you are finding out.

It’s a bit like taking the engine from a Toyota, the gear box from a Volks Wagon, the wheels from a Honda, the steering wheel from a Ferrari and the battery from your flash light and then wondering :scratch: why the car won’t start when you turn the key :slight_smile:

Is this for some sort of homework assignment or for a “real life” website?