identify.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. include "auth.php";
  3. include "qrcode.php";
  4. if (isset($_POST['max'])) {
  5. $max = htmlentities(mysqli_real_escape_string($link, $_POST['max']));
  6. $query = "SELECT name FROM devices WHERE id= $max";
  7. $result = mysqli_query($link, $query) or die("Ошибка " . mysqli_error($link));
  8. $res1 = mysqli_fetch_array($result);
  9. if ($res1['name']!="")
  10. {
  11. echo "valid";
  12. }
  13. else
  14. {
  15. echo "invalid";
  16. }
  17. }
  18. if(isset($_GET['company']) && isset($_GET['name']) && isset($_GET['id'])){
  19. $name = htmlentities(mysqli_real_escape_string($link, $_GET['name']));
  20. $os=getOS();
  21. $id = htmlentities(mysqli_real_escape_string($link, $_GET['id']));
  22. $company = htmlentities(mysqli_real_escape_string($link, $_GET['company']));
  23. $query = "INSERT INTO devices VALUES('$id','$os','$company','$name', NOW())";
  24. $result = mysqli_query($link, $query) or die("Ошибка " . mysqli_error($link));
  25. $query = "SELECT * FROM devices WHERE id= $id";
  26. $result = mysqli_query($link, $query) or die("Ошибка " . mysqli_error($link));
  27. while ($res12 = mysqli_fetch_array($result)) {
  28. $codeID = $res12['id'] . $res12['os'] . $res12['company_id'] . $res12['name'];
  29. }
  30. echo $codeID;
  31. $dateToBin=pack("Cl*",$codeID);
  32. $datebase64=base64_encode($dateToBin);
  33. // $datebase64=base64_encode($codeID);
  34. $query = "INSERT INTO device_requests VALUES(NULL,'$datebase64',NOW())";
  35. $result = mysqli_query($link, $query) or die("Ошибка " . mysqli_error($link));
  36. /*
  37. $id_remove=$id;
  38. $query = "DELETE FROM devices WHERE id='$id_remove'";
  39. $result = mysqli_query($link, $query) or die("Ошибка " . mysqli_error($link));
  40. echo "true";
  41. */
  42. }
  43. $user_agent = $_SERVER['HTTP_USER_AGENT'];
  44. function getOS()
  45. {
  46. global $user_agent;
  47. $os_platform = "Unknown OS Platform";
  48. $os_array = array(
  49. '/windows nt 10/i' => 'Windows 10',
  50. '/windows nt 6.3/i' => 'Windows 8.1',
  51. '/windows nt 6.2/i' => 'Windows 8',
  52. '/windows nt 6.1/i' => 'Windows 7',
  53. '/windows nt 6.0/i' => 'Windows Vista',
  54. '/windows nt 5.2/i' => 'Windows Server 2003/XP x64',
  55. '/windows nt 5.1/i' => 'Windows XP',
  56. '/windows xp/i' => 'Windows XP',
  57. '/windows nt 5.0/i' => 'Windows 2000',
  58. '/windows me/i' => 'Windows ME',
  59. '/win98/i' => 'Windows 98',
  60. '/win95/i' => 'Windows 95',
  61. '/win16/i' => 'Windows 3.11',
  62. '/macintosh|mac os x/i' => 'Mac OS X',
  63. '/mac_powerpc/i' => 'Mac OS 9',
  64. '/linux/i' => 'Linux',
  65. '/ubuntu/i' => 'Ubuntu',
  66. '/iphone/i' => 'iPhone',
  67. '/ipod/i' => 'iPod',
  68. '/ipad/i' => 'iPad',
  69. '/android/i' => 'Android',
  70. '/blackberry/i' => 'BlackBerry',
  71. '/webos/i' => 'Mobile'
  72. );
  73. foreach ($os_array as $regex => $value) {
  74. if (preg_match($regex, $user_agent)) {
  75. $os_platform = $value;
  76. }
  77. }
  78. return $os_platform;
  79. }
  80. ?>