CALLS_PHP

This is a site using PHP which incorporates MySQL, this is the full code separated in four files, one is index.php, two is login.php, three is loginprocess.php and forth is calls.php. This is a site which simply after logging in displays the phone calls to my home phone number from the CALLERIDNET program


This is the default file which loads the login.php

inex.php


<?php
//index.php
This is a program which once loged on
will allow to display the phone calls to
an address created by CALLERIDNET using a 
mysql dtabase */

session_start();
if (!isset($_SESSION["login"]))

    header("location:login.php");
?>


This is the login file in html which checks the validity of the input and loads the loginprocess.php

login.php


<html>
<?php  //login.php
?>



<center>
    <fieldset>
        <legend>Login </legend>
        <form action="loginprocess.php" method="POST"><br> <br> 
            Username:<input type="text"
 required="" name="uname"><br> <br> 
            Password:<input type="password"
 required="" name="upassword"><br> <br> 
            <input type="submit"
 value="Login" name="sub">
            <br> 
            <?php
            if (isset($_REQUEST["
err"]))
                $msg = "
Invalid username or Password";
            ?>
            <p style="color:red;">
                <?php if (isset($msg)) {

                    echo $msg;
                }
                ?>

            </p>

        </form>

    </fieldset>
</center>

</html>


This is the loginprocess file which verifies if it is the correct username and password and if so loads the calls.php, if not it loads the login.php

loginprocess.php


<?php
//loginprocess.php
session_start();
include("config.php");

if (isset($_REQUEST['sub'])) {
    $a = $_REQUEST['uname'];
    $b = $_REQUEST['upassword'];

    //$res = mysqli_query($cser,"select* from users where uname='$a'and upassword='$b'");
    //$result=mysqli_fetch_array($res);

    $result = false;

    if ($a == 'username' && $b = "password") $result = true;
    if ($result) {

        $_SESSION["login"] = "1";
        header("location:calls.php");
    } else {
        header("location:login.php?err=1");
    }
}



This is the calls file which displays a mysql table called phonecalls in a html

calls.php


<?php
//calls.php
session_start();
//session_destroy();
?>
<html>


    <title>Calls</title>
    <meta name='viewport' content='width=device-width, initial-scale=1' />
    <meta http-equiv='content-type' content='text/html; charset=utf-8' />
    <meta name='author' content='Richard Perreault' />
    <meta name='description' content='Bienvenue sur mon site privé' />
    <meta charset='utf-8' />
    <!-- Document title -->
    <!-- Stylesheets & Fonts -->
    <link href='css/plugins.css' rel='stylesheet' />
    <link href='css/style.css' rel='stylesheet' />


<body>
    <div class='post-item border'>
        <div class='post-item-wrap'>

            <?php if ($_SESSION['login'] == 1) { ?>

                <h1 align='center'><span  lang='en-ca'>Calls Received</h1>
                <table border='0' width='100%' height='48'>
                    <tr>
                        <td width='11%' height='17' style='border-bottom-style: solid' bgcolor='#5D7B9D'>
                            <span  lang='en-ca'>
                                <font color='#FFFFFF'>Date</font>
                            </span>
                        </td>
                        <td width='11%' height='17' style='border-bottom-style: solid' bgcolor='#5D7B9D'>
                            <span  lang='en-ca'>
                                <font color='#FFFFFF'>Number</font>
                            </span>
                        </td>
                        <td width='11%' height='17' style='border-bottom-style: solid' bgcolor='#5D7B9D'>
                            <span  lang='en-ca'>
                                <font color='#FFFFFF'>Name</font>
                            </span>
                    </tr>
                    <?php Populate()
                    ?>
                </table>
        </div>
    </div>
<?php } else header('location:login.php'); ?>

</html>

<?php function Populate()
{
    $username = 'username';
    $password = 'password';
    $hostname = 'hostname';
    $database = 'database';

    //connection to the mysql database,
    $dbhandle = mysqli_connect($hostname, $username, $password, $database)
        or die('Unable to connect to MySQL');
    //echo 'Connected to MySQL<br> ';

    //execute the SQL Statement
    $result = mysqli_query($dbhandle, 'SELECT name, phonenumber, calldate, BLOCKED FROM phonecalls ORDER BY calldate DESC');

    $DoBkgrnd = true;

    //fetch the data from the database 
    while ($row = mysqli_fetch_array($result)) {
        $blocked = $row['BLOCKED'];

        if ($DoBkgrnd) {
            echo ('<tr>');
            echo ('<td width = \'11%\' height = \'19\' bgcolor = \'#F7F6F3\'>' . $row['calldate'] . '</td>');
            echo ('<td width = \'11%\' height = \'19\' bgcolor = \'#F7F6F3\'>' . $row['phonenumber'] . '</td>');
            echo ('<td width = \'11%\' height = \'19\' bgcolor = \'#F7F6F3\'>' . $row['name'] . '</td>');
            if ($blocked)
                echo ('<td width = \'11%\' height = \'19\' bgcolor = \'#F7F6F3\'>BLOCKED</td>');
            echo ('</tr>');
            $DoBkgrnd = false;
        } else {
            echo ('<tr>');
            echo ('<td width = \'11%\' height = \'19\'>' . $row['calldate'] . '</td>');
            echo ('<td width = \'11%\' height = \'19\'>' . $row['phonenumber'] . '</td>');
            echo ('<td width = \'11%\' height = \'19\'>' . $row['name'] . '</td>');
            if ($blocked)
                echo ('<td width = \'11%\' height = \'19\'>BLOCKED</td>');
            echo ('</tr>');
            $DoBkgrnd = true;
        }
    }

    //close the connection
    mysqli_close($dbhandle);
    session_destroy();
}

?>