Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php get screen size

//Save in cookie to access with $_COOKIE["screenXYZ"];

//SetScreenResToCookie.php
<?php
if (isset($_POST)) {
    echo "success";
    setcookie("screenW", $_POST["screenWidth"], time() + (86400 * 30), '/');
    setcookie("screenH", $_POST["screenHeight"], time() + (86400 * 30), '/');
} else {
    echo "Error. $" . "_POST array is not set!";
}
?>
  
//where u need the Screen res(only a example):
  
//header.php
//The function 
<?php
function screenResToCookie()
{
 if (isset($_SERVER["HTTP_X_FORWARDED_PROTO"])) {
        $http = $_SERVER["HTTP_X_FORWARDED_PROTO"];
    } else {
        $http = $_SERVER["REQUEST_SCHEME"];
    }
    $url = $http . "://" . $_SERVER["HTTP_HOST"];
    echo "<script>
        var damn = setInterval(() => {
            var formData = {
                screenWidth: screen.width,
                screenHeight: screen.height
            };

            $.ajax({
                url: '" . $url ."/.../SetJScookie.php?" . time() ."',//This needs to be the URL on the domain u access the website from. ajax dont allow HTTPS
                type: 'POST',//because 'SetScreenResToCookie.php' use POST Array
                data: formData, //data in json format
                async: false, //enable or disable async (optional, but suggested as false if you need to populate data afterwards)
                success: function(response, textStatus, jqXHR) {
                    console.log(response);
                },
                error: function(jqXHR, textStatus, errorThrown) {
                    console.log(jqXHR);
                    console.log(textStatus);
                    console.log(errorThrown);
                }
            });
        }, 1000);
    </script>";
}

function ReturnHeader($..., $...) {
  $Mobile = false;//If we dont wanne use Bootstrap or @media
  screenResToCookie();//set the cookie for us
  if (intval($_COOKIE["screenW"]) < 735) {
        $Mobile = true;
    }
  
  if ($Mobile) {
	//print header with mobile style(Dropdowns added or whatever)
  } else {
   //print header with Computer/Tablet style 
  }
}
?>

Comment

php get screen width

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction() {
  var x = "Total Width: " + screen.width + "px";
  document.getElementById("demo").innerHTML = x;
}
</script>
Comment

PREVIOUS NEXT
Code Example
Php :: laravel make migration 
Php :: convert string to int php 
Php :: random String Function PHP 
Php :: laravel if else condition in query 
Php :: how to change the colum type in migration laravel 
Php :: find string lenght in php 
Php :: artisan command to add resources to controller 
Php :: last insert id in laravel 
Php :: Write a php program to swap two numbers using temporary variable 
Php :: laravel share 
Php :: logout all the users from site wordpress 
Php :: laravel remove index.php from url 
Php :: php forech pdo 
Php :: change php version 
Java :: java how to output to a executable 
Java :: java create jframe 
Java :: save map to file java 
Java :: random item from arraylist 
Java :: java get excectuon time 
Java :: java reflection get field value 
Java :: objectmapper maven dependency 
Java :: install java in wsl2 
Java :: how to install java 8 on aws linux 
Java :: How to implement a Trie data structures in Java? 
Java :: convert java date to sql date 
Java :: java GUI jframe text 
Java :: java get ram usage 
Java :: how to install java runtime environment on centos 7 
Java :: fullscreen java jframe 
Java :: How to find the fibonacci of an integer value iteratively in Java? 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =