This question already has an answer here:
Im creating a script that puts the users device information and their IP into a database here is the script I am using. I keep getting this big amount of info for the user agent and I want to just make it insert in the database saying "iPhone" "Android" "Computer" instead of all that complicated stuff, how would i do that? UPDATE: Oh and the affsub is the tracking id.
<?php
$servername = "localhost";
$username = "user";
$password = "pass";
$dbname = "db";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
date_default_timezone_set('America/New_York');
$affsub = $_GET['affsub'];
$userip = $_SERVER['REMOTE_ADDR'];
$userdevice = $_SERVER['HTTP_USER_AGENT'];
$date = date('Y-m-d');
$time = date('H:i:s');
$sql = "INSERT INTO clicks (affsub, userip, userdevice, date, time)
VALUES ('$affsub', '$userip', '$userdevice', '$date', '$time')";
if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
header("Location: linkgoeshere"); /* Redirect browser */
exit();
?>
THIS IS NOT A DUPLICATE OF THE IP ONE I am trying to get the users device NOT their IP, I can already do that perfectly fine.
</div>