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

screen size to php

//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

PREVIOUS NEXT
Code Example
Php :: php iframe add content 
Php :: wordpress if page 
Php :: php function use 
Php :: PHP multidimensional array merge recursive 
Php :: Laravel Excel check if column exists 
Php :: laravel validation messages 
Php :: CODEIGNITER codeigniter 4 auth 
Php :: decrypted password php 
Php :: php barcode generator 
Php :: Logging a Massage php 
Php :: laravel where json array column 
Php :: php object to json 
Php :: php is closure 
Php :: guzzle login example 
Php :: define function in php 
Php :: date comparison function in php 
Php :: scss laravel 
Php :: php inner join array 
Php :: create laravel update 
Php :: controller class does not exist laravel 
Php :: phpunit run one test 
Php :: foreign key string laravel 
Php :: php loop object keys 
Php :: merge strings in php 
Php :: laravel debugbar ServiceProvider to the providers 
Php :: upload image to mysqli database 
Php :: wherenotnull laravel 
Php :: export laravel path fedora 
Php :: Wampserver does not use, modify or require the PATH environment variable. 
Php :: radio button in php form 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =