Project Online Examination System in PHP & Java Script User ID and Password Send On Email Id

 


Source Code :

Index.php:

<!DOCTYPE html>

<html>

<head>

<meta name="viewport" content="width=device-width, initial-scale=1" />

<style>

   * {

      box-sizing: border-box;

   }

   body {

      margin: 0;

      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;

      background: url();

   }

   nav {

      font-size: 20px;

      background-color: rgb(136, 22, 182);

      color: #cccccc;

      height: 75px;

   }

   ul {

      position: fixed;

      right:10px;

   }

   ul li {

      display: inline;

      padding-right: 30px;

      font-weight: 500;

      color: rgb(251, 255, 0);

   }

   ul li a

   {

    text-decoration: none;

    display: inline;

      padding-right: 30px;

      font-weight: 500;

      color: rgb(251, 255, 0);

   }

   .logo {

      width: 75%;

      margin-left: auto;

      margin-right: auto;

      color: white;

      float: left;

      font-size: 30px;

      padding-left: 20px;

      padding-top: 20px;

   }

   

      footer {

      color: white;

      position: fixed;

      width: 100%;

      bottom: 0;

      margin-left: auto;

      margin-right: auto;

      font-size: 30px;

      height: 100px;

      padding: 20px;

      background-color: rgb(9, 141, 101);

      text-align: center;

   }

   footer a

   {

      text-decoration: none;

      color:white;

      display: inline;

      padding-right: 25px;

      font-weight: 400;

      color: rgb(251, 255, 0);

   

   }

</style>

</head>

<body onload="autoslide()">

<nav>

<div class="logo">

ONLINE EXAMINATION

</div>

<ul>

<li><a href="#">Home</a></li>

<li><a href="#">About</a></li>

<li><a href="signinup.php">Login</a></li>

</ul>

</nav>

<img src="1.png" id="pic" height="500px" width="1365px"></img>

<script>

var a=1;

function nextpic()

{

if(a>=7)

{

a=1;

}

else

{

a=a+1;

}


document.getElementById("pic").src=a+".png";

}


function autoslide()

{

setInterval(nextpic,3000);

}

</script> 


<footer>

Copyright © 2021 Online Examination<br>

<a href="">Contact Us</a>

<a href="">Disclaimer</a>

<a href="">Terms & Conditions </a>

<a href="">Privacy Policy</a>

</footer>

</body>

</html>


Login.php



<!DOCTYPE html>

<html>

<head>

<title>Login Page</title>

<link rel="stylesheet" a href="style.css"/>

<link rel="stylesheet" a href="css3\font-awesome.min.css"/>

</head>

<body bgcolor="grey">


<div class="container">

<h1>Login Form</h1>

<form method="post">

<div class="form_input">

USERNAME:

<input type="text" name="txtun" placeholder="Enter your User id " required="">

</div>

<div class="form_input">

PASSWORD: <input type="password" name="txtup" placeholder="Password" id="myInput"><br>

<input type="checkbox" onclick="myFunction()">Show Password


<script>

function myFunction() {

  var x = document.getElementById("myInput");

  if (x.type === "password") {

    x.type = "text";

  } else {

    x.type = "password";

  }

}

</script>

</div>

<input type="checkbox" name="chk">Remember Password?<br>

<input type="submit" name="btn" value="Login" class="btn-login">

<a href="signup.php" class="btn-login">New User| Sign Up |</a><br>

<a href="">Forget Password ? </a>

</form>

</div>

<?php

if(isset($_POST["btn"]))

{

$d=$_POST['txtun'];

$e=$_POST['txtup'];

$con=mysqli_connect("localhost","root","","examonline");


if($con)

{

$q="SELECT * FROM `signup` where userid='$d' and password='$e'";

$r=mysqli_query($con,$q);

$c=mysqli_num_rows($r);


if($c>0)

{

echo "<script>alert('Login Successfully')</script>";

header("Location:timer.php");

}

else

{

echo "<script>alert('Invalid Login')</script>";

}

}

else

{

echo "<script>alert('Not Connected')</script>";

}

}


?>

<script>

   document.write(Date());

</script>

</body>

</html>


Signup.php



<!DOCTYPE html>
<html>
<head>
<title>Registration Form</title>
<link rel="stylesheet" a href="style1.css"/>
</head>
<body>

<div id="xyz">
<form method="post">
            <h1>Registration Form</h1>
<label><b>Name:</b></label>
<input type="text" name="txt" placeholder="User Name" required=""><br><br>
<label><b>E-mail Id:</b></label>
<input type="text" name="emd" placeholder="xxx@gmail.com" required=""><br><br>
<label><b>Mobile No:</b></label>
<input type="text" name="mob" placeholder="+91 xxxxxxxxxx" required=""><br><br>
<label><b>User id:</b></label>
<input type="text" name="usd" placeholder="Create User Id" required=""><br><br>
<label><b>Password:</b></label>
<input type="password" name="pass" placeholder="Create Password" required=""><br><br>
<button type="submit" name="btn" value="Submit" class="btn-login">SIGNUP</button><br><br>
<a href="signinup.php">Are You Registered ? : Login</a>
<a href="index.php">Cancel</a>
</form>
</div>
<?php
 if(isset($_POST["btn"]))
{
$a=$_POST["txt"];
$b=$_POST["emd"];
$c=$_POST["mob"];
$d=$_POST["usd"];
$e=$_POST["pass"];
$con=mysqli_connect("localhost","root","","examonline");
// echo "a=".$a."<br>";
// echo "b=".$b."<br>";
if($con)
{
$q="INSERT INTO `signup` (`Name`, `Email`, `Mobile`, `userid`, `password`) VALUES ('$a', '$b', '$c', '$d', '$e');";
// ` backquote
$r=mysqli_query($con,$q);
if($r)
{
echo "<script>alert('User Id & Password Send on E-mail Successfully')</script>";
}
else
{
echo "Not Added";
}
}
else
{
echo "Not connect";
}
mysqli_close($con);
}
?>

<?php
if(isset($_POST["btn"])){
$from="Online Exam";
$webmaster="Welcome Online Exam";
$to=$_POST["emd"];
$headers=$from."<".$to.">";
$message="Your Username is: ".$_POST["usd"]." and Your Password is : ".$_POST["pass"];
if(mail($headers,$webmaster,$message))
{
  
  }
else
{

}
}
?>
</body>
</html>

Style.css

body{
margin: 0 auto;
background-image: url("../image/xyz.jpg");
background-repeat: no-repeat;
background-size: 100% 720px;
background-color:;
    margin-top: 100px;
}
.container{
width: 700px;
height: 350px;
text-align: center;
margin:10px;
color: yellow;
font-size: 25px;
background-color: rgba(44,62,80,0.7);
border-radius: 04px;
margin:10px 15px 10px 300px ;
box-shadow: 5px 10px 20px black inset;
}
.container a
{
text-decoration: none;
color: yellow;
}
 .btn-login{
  background-color: #4CAF50;
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
}
.form_input
{
padding: 10px 25px 10px 15px;
}

Style1.css

/*add full-width input fields*/
body{
background-color: grey;
}
input[type=text],
input[type=password] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 2px solid #ccc;
box-sizing: border-box;
}
button {
background-color: Green;
color: white;
padding: 15px 20px;
margin: 8px 0;
cursor: pointer;
width: 100%;
}
#xyz
{
height: 200px;
width: 500px;
margin: 800px;
text-align: center;
color: yellow;
margin-top: 25px;
    margin-bottom: 25px;
    font-size:15px;
}
#xyz a
{
text-decoration: none;
color:White;
background-color: rgb(9,141,101);
font-size:25px;
}
#label
{
margin-left: 10px;
}

Sendmail.php

<?php
$to_email = "oexam7006@gmail.com";
$subject = "Email Test via PHP using Localhost";
$body = "Hi Hell Good Morning ";
$headers = "From:rockbusiness2021@gmail.com";

if(mail($to_email, $subject, $body, $headers)) {
    echo "Email sent successfully to $to_email...";
}else{
    echo "Sorry, failed while sending mail!";
}
?>

Setting in Xampp PHP File SMTP Find Php under Configaration Php.ini


Setting in Xampp PHP sendmail under Configration

; configuration for fake sendmail

; if this file doesn't exist, sendmail.exe will look for the settings in
; the registry, under HKLM\Software\Sendmail

[sendmail]

; you must change mail.mydomain.com to your smtp server,
; or to IIS's "pickup" directory.  (generally C:\Inetpub\mailroot\Pickup)
; emails delivered via IIS's pickup directory cause sendmail to
; run quicker, but you won't get error messages back to the calling
; application.

smtp_server=smtp.gmail.com

; smtp port (normally 25)

smtp_port=587

; SMTPS (SSL) support
;   auto = use SSL for port 465, otherwise try to use TLS
;   ssl  = alway use SSL
;   tls  = always use TLS
;   none = never try to use SSL

smtp_ssl=auto

; the default domain for this server will be read from the registry
; this will be appended to email addresses when one isn't provided
; if you want to override the value in the registry, uncomment and modify

;default_domain=mydomain.com

; log smtp errors to error.log (defaults to same directory as sendmail.exe)
; uncomment to enable logging

error_logfile=error.log

; create debug log as debug.log (defaults to same directory as sendmail.exe)
; uncomment to enable debugging

debug_logfile=debug.log

; if your smtp server requires authentication, modify the following two lines

auth_username=rockbusiness2021@gmail.com
auth_password=Email Password

; if your smtp server uses pop3 before smtp authentication, modify the 
; following three lines.  do not enable unless it is required.

pop3_server=
pop3_username=
pop3_password=

; force the sender to always be the following email address
; this will only affect the "MAIL FROM" command, it won't modify 
; the "From: " header of the message content

force_sender=rockbusiness2021@gmail.com

; force the sender to always be the following email address
; this will only affect the "RCTP TO" command, it won't modify 
; the "To: " header of the message content

force_recipient=

; sendmail will use your hostname and your default_domain in the ehlo/helo
; smtp greeting.  you can manually set the ehlo/helo name if required

hostname=

Setting in Gmail SMTP Enable




Google Security ON




Timer.php
<body onload="starttime()">

  <div id="Holder">
    <div id="Header"></div>
    <div id="NavBar">
      <nav>
        <ul>
          <li><a href="signinup.php"> Login</a></li>
          <li><a href="signinup.php">Registration</a></li>
        </ul>
    </div>
    <div id="Content">
      <div id="PageHeading">
        <h1><marquee direction="right" behavior="alternate">All the Best</marquee></h1>
      </div>

      <div id="ContentLeft">
        <h2></h2>
        <br>
        <img id="online_start">
        <br>
        <h6>Online Examination System(OES) is a Multiple Choice Questions(MCQ) based 
examination system that provides an easy to use environment for both 
Test Conducters and Students appearing for Examination.</h6>
      </div>
      <div id="ContentRight">
        <section class="loginform_cf">
          <table>
            <tr>
              <td id="test_status" style="text-align:left"></td>
              <td id="starttime" style="text-align:right"></td>
            </tr>

            <tr>
              <td id="test" colspan="2"></td>
            </tr>

          </table>
          <div id="showtime"></div>
        </section>
      </div>

    </div>


    <div id="Footer">Developed by - Ranjeet Kumar </div>
  </div>

  <script>
    var pos = 0,
      test, test_status, question, choice, choices, chA, chB, chC, correct = 0;

    var questions = [
      ["Which of the following a is not a keyword in Java ?", "class", "interface", "extends", "C"],

      ["Which of the following is an interface ?", "Thread", "Date", "Calender", "A"],

      ["Which company released Java Version 8 ?", "Sun", "Oracle", "Adobe", "A"],

      ["What is the length of Java datatype int ?", "32 bit", "16 bit", "None", "C"],

      ["What is the default value of Java datatype boolean?", "true", "false", "0", "A"]
    ];

    function _(x) {
      return document.getElementById(x);
    }

    function renderQuestion() {
      test = _("test");

      var showscore = Math.round(correct / questions.length * 100);


      if (pos >= questions.length) {
        document.getElementById("online_start").src = "animatedthankyou.gif";

        test.innerHTML = "<h3>You got " + correct + " correct of " + questions.length + " questions</h3>";
        test.innerHTML += "<h3> Your Grade : " + showscore + "% </h3>";
        test.innerHTML += "<h4>Exam Finished in Time:" + sec + " Seconds</h4>";
        test.innerHTML += "<button onclick='EndExam()'>End the Exam</button>";
        _("test_status").innerHTML = "<h3>Test Completed</h3>";
        pos = 0;
        correct = 0;



        clearTimeout(tim);
        //document.getElementById("endtime").innerHTML = "<h4>Finished Time:"+min+" Minutes :" + sec+" Seconds</h4>";
        document.getElementById("starttime").style.display += 'none';
        document.getElementById("showtime").style.display += 'none';
        //document.getElementById("showtime").style.display += 'block';


        return false;
      }
      _("test_status").innerHTML = "<h3>Question " + (pos + 1) + " of " + questions.length + "</h3>";
      question = questions[pos][0];
      chA = questions[pos][1];
      chB = questions[pos][2];
      chC = questions[pos][3];
      test.innerHTML = "<h3>" + question + "</h3>";
      test.innerHTML += "<input type='radio' name='choices' value='A'> " + chA + "<br>";
      test.innerHTML += "<input type='radio' name='choices' value='B'> " + chB + "<br>";
      test.innerHTML += "<input type='radio' name='choices' value='C'> " + chC + "<br><br>";
      test.innerHTML += "<button onclick='checkAnswer()'>Next</button><br><br>";


    }

    function checkAnswer() {
      choices = document.getElementsByName("choices");
      choice = -1;
      for (var i = 0; i < choices.length; i++) {
        if (choices[i].checked) {
          choice = choices[i].value;
        }
      }
      if (choice == questions[pos][4]) {
        correct++;
      }
      pos++;
      renderQuestion();
    }

    window.addEventListener("load", renderQuestion, false);


    function EndExam() {

      location.href = "index.php";
    }


    var tim;
    var showscore = Math.round(correct / questions.length * 100);
    var min = 1;
    var sec = 60;
    var f = new Date();

    function starttime() {
      showtime();
      document.getElementById("starttime").innerHTML = "<h4>You started your Exam at " + f.getHours() + ":" + f.getMinutes() + "</h4>";
    }

    function showtime() {
      if (parseInt(sec) > 0) {
        sec = parseInt(sec) - 1;
        document.getElementById("showtime").innerHTML = "Your Left Time is :" + min + " Minutes :" + sec + " Seconds";
        tim = setTimeout("showtime()", 1000);
      } else {
        if (parseInt(sec) == 0) {
          min = parseInt(min) - 1;
          document.getElementById("showtime").innerHTML = "Your Left Time is :" + min + " Minutes :" + sec + " Seconds";
          if (parseInt(min) == 0) {
            clearTimeout(tim);
            alert("Time Up");


            /*_("test_status").innerHTML = "Test Completed";
            test.innerHTML = "<h2>You got "+correct+" of "+questions.length+" questions correct</h2>";
            test.innerHTML = "<h2>You got "+showscore +"% out of "+questions.length+"</h2>";
            test.innerHTML = "<button onclick='EndExam()'>End the Exam</button>";
            pos = 0;
            correct = 0;
            clearTimeout(tim);
            document.getElementById("endtime").innerHTML = "You Finished exam at Time is :"+min+" Minutes :" + sec+" Seconds";
            document.getElementById("starttime").style.display += 'none';
            document.getElementById("showtime").style.display += 'none';
            //document.getElementById("showtime").style.display += 'block';
            return false;*/

            window.location.href = "index.php";
          } else {
            sec = 60;
            document.getElementById("showtime").innerHTML = "Your Left Time is :" + min + " Minutes :" + sec + " Seconds";
            tim = setTimeout("showtime()", 1000);
          }
        }

      }
    }

  </script>

</body>

</html>




Comments