How do I create cookies which save the user agent and it's IP address at my login page. When I login, it will be save into my database row as IP and Agent. The login page match the current IP and Agent to with database saved data.
If data match login success else redirect to abcd.com.
Here I can make this code but I not under how to add cookies please help and try to make this.
My code is below:
<?php
$msg = "";
if (isset($_POST['submit'])) {
$con = new mysqli('localhost', 'research_emailC', 'test123', 'research_phpEmailConfirmation');
$email = $con->real_escape_string($_POST['email']);
$password = $con->real_escape_string($_POST['password']);
if ($email == "" || $password == "")
$msg = "Please check your inputs!";
else {
$sql = $con->query("SELECT id, password, isEmailConfirmed FROM users WHERE email='$email'");
if ($sql->num_rows > 0) {
$data = $sql->fetch_array();
if (password_verify($password, $data['password'])) {
if ($data['isEmailConfirmed'] == 0)
$msg = "Please verify your email!";
else {
$msg = "You have been logged in";
}
} else
$msg = "Please check your inputs!";
} else {
$msg = "Please check your inputs!";
}
}
}
?>