Detects whether the browser’s devtools are open

i trying Detects whether the browser’s devtools are open using php. I using user-agent to detect platform is mobile/talblet and desktop. If platform is mobile/tablet then redirect to my website and platform is desktop then alert user on desktop mode.
At the same time I want to check devtools is open. The reason for this is that I don’t want users to use mobile mode to pass the test.

It’s working better when mobile/tablet and desktop but the script not working when users use mobile mode on DevTools. This is my problem. I have found [https://github.com/david-fong/detect-devtools-via-debugger-heartstop][1] and demo: [https://david-fong.github.io/detect-devtools-via-debugger-heartstop/][1]. it works fine for me. However, I don’t know how to use it on hosting file php. Can someone help me? Sorry for my English is very bad.

this is my script

<?php
$user_agent = $_SERVER['HTTP_USER_AGENT'];

if (strpos($user_agent, 'Mobile') !== false || strpos($user_agent, 'Tablet') !== false) {
    header("Location: example.com");
} else {
    echo "Desktop Mode";
}

echo "<script>";
echo "console.log(Object.defineProperties(new Error, {";
echo "toString: {value() {(new Error).stack.includes('toString@') && alert('Safari devtools')}},";
echo "message: {get() {window.close()}}";
echo "}));";
echo "</script>";
?>