Friday, 18 November 2016

connection file

<?php
$db_username = "devoizxg_machins"; //Database Username
$db_password = "(pWLB=(TS-%d"; //Database Password
$hostname = "localhost"; //Mysql Hostname
$db_name = 'devoizxg_machinetool'; //Database Name

$con = new mysqli($hostname, $db_username, $db_password, $db_name);
if ($con->connect_error) {
    die("Connection failed:" . $con->connect_error);
}
?>

on every page header

    <?php
ob_start();
require 'connection.php';
session_start();
if ( isset($_SESSION['a_loggedin']) && $_SESSION['a_loggedin'] == true)
    {
        $useremail = $_SESSION['a_email'];
        $sql999="SELECT * from `admin` where email='".$useremail ."'";
        $result999 = mysqli_query($con, $sql999);
        if(mysqli_num_rows($result999)>0)
            {
                while($row999 = mysqli_fetch_assoc($result999))
                    {   
                        $id = $row999['id'];
                        $imagee = $row999['imagee'];
                       
                    }
            }
    }
else
    {
        header('Location:a_loginform.php');
    }
?>

a_logout

<?php
// Initialize the session.
// If you are using session_name("something"), don't forget it now!
session_start();

// Unset all of the session variables.
$_SESSION = array();

// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (ini_get("session.use_cookies")) {
    $params = session_get_cookie_params();
    setcookie(session_name(), '', time() - 42000,
        $params["path"], $params["domain"],
        $params["secure"], $params["httponly"]
    );
}

// Finally, destroy the session.
session_destroy();
header("Location: a_loginform.php");
?>

a_loginform

<?php
ob_start();
require 'connection.php';
session_start();

 if(isset( $_POST['submit1'] ) )
    {
   
        $email = mysqli_real_escape_string($con, $_POST['email']);
        //$email1 = $_GET['email']);
        $password = mysqli_real_escape_string($con, $_POST['password']);
        //$password1 = $_GET['password']);
        $result = mysqli_real_escape_string($con, $_POST['result']);
       
       
        $sql = "SELECT * FROM admin where email='".$email."' and password='".$password."' ";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0)
    {
        $_SESSION['a_loggedin'] = true;
        $_SESSION['a_email'] = $email;
        //header("Location:a_dashboard.php");
        header("Location:a_dashboard.php");
    }
               
                else
                    {
                        header("Location:a_loginform.php");
                    }
                       
    }
?>


            <form name="form"  action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"  method="post">
              <span style="color:red; margin-left:-13px;">*</style></span> <input type="email" name="email" placeholder="Email" id="formTemplate" required/>
              <? if($err1!=""){ echo $err1; }?>
              <span style="color:red; margin-left:-13px;">*</style></span><input type="password" name="password" placeholder="Password" required/>
             <input type="hidden" name="result" value="<? echo $_SESSION["result"];?>">
              <button name="submit1">Login</button>
           
            </form>