Streaming live at 10am (PST)

Set cookies and compare in PHP


#1

I want create a code when last login device or ip change it would be show result like this in my code. But looks something is mistake in my code causes it shows always good message even it is wrong

How I make a cookies which save current user agent or ip and compare it which save into database if both are match alert will be good else bad.

<?php 
$ip = $_SERVER['REMOTE_ADDR'];
$agent = $_SERVER['HTTP_USER_AGENT'];
setcookie('type_id', $agent, $ip, $cookie_value, time() + (86400 * 10), "/"); //set cookies of 10 days
    
$current = setcookie('type_id', $agent, $ip, $cookie_value, time() + (86400 * 10), "/"); 

//below $past is saved agent and IP details in database
if ($current!=$past) {
    echo "Last login device changed additional error !";
}else{
    echo "everything is good additional fine";
}
?>

Thank you advanced.


#2

This is a Webflow forum. You could ask PHP questions on Stack Overflow instead.


#3

I know where is I am. Code have not family and this is forum have authority to ask about code.