How can PHP scripts differentiate between a user accessing a website from a PC or a mobile device?

To differentiate between a user accessing a website from a PC or a mobile device, you can use the $_SERVER['HTTP_USER_AGENT'] variable in PHP. This variable contains information about the user's browser and device. By parsing this information, you can determine if the user is accessing the website from a mobile device or a PC.

$user_agent = $_SERVER['HTTP_USER_AGENT'];

if (strpos($user_agent, 'Mobile') !== false) {
    // User is accessing the website from a mobile device
    echo "Mobile device detected";
} else {
    // User is accessing the website from a PC
    echo "PC detected";
}