-2

I want to retrieve the screen size of my screen in PHP . I want to say in my file php :

if(screenSize==1024x600){ ... }

I know how i can retrieve resolution in JS but how i can use it in PHP ?!

Thanks for advance !

gadjeel
  • 21
  • 1
  • 5
  • 1
    PHP is a server-side language so you can't get the screen size using it. Also, this question was already asked before, so you should search before asking a question: http://stackoverflow.com/questions/1504459/getting-the-screen-resolution-using-php – Mihai Matei Mar 22 '17 at 08:07

2 Answers2

1

You can get the screen resolution with Javascript and post it to your server as a parameter. Then, on PHP you will receive it as a POST parameter and store it in your $_SESSION

$_SESSION["resolution"] = $_POST["resolution"];

Later you will be able to use this value referring $_SESSION["resolution"].

You might want to be able to detect changes, so you could have this code

<script type="text/javascript">
    var resolution = <?php echo ((session_status() != PHP_SESSION_NONE) && (isset($_SESSION["resolution"]))) ? $_SESSION["resolution"] : "undefined;" ?>;
    //Get the current resolution, compare it to resolution and if different, POST it to the server
</script>

The only problem remaining is that resolution will not be known in the very first request, but you will be able to solve it either by reloading the page after the first calculation or handling anything related to it inside the callback of the POST request.

Lajos Arpad
  • 45,912
  • 26
  • 82
  • 148
0

You cant. 'cause screenSize is browser's property. php is server side. Can not know that property.

But you can retrieve information with javascript and send it to php with an http request.

sensorario
  • 15,862
  • 24
  • 85
  • 131