Jump to content
xisto Community
kservice

How To Put Ina Php Var The Screen Width?

Recommended Posts

Hello, i need tu put in $width (a php variable), the screen width of the client, and then do some arithmetics operations with it,

I did this :

$width = " <script>document.write(screen.width); </script>"; I tested if $width get the value, with this:echo $width;And, is ok, but when i multiply $width with any value, I got $width = 0;example;My Screen is at 1024 by 768 so:$width = "<script>document.write(screen.width); </script>"; echo $width; ---------------> 1024$width = $width * 2; echo $width; ------------------> 0

Please, Can someone tell me why? and is there a manner to do this!!

Thank's

kservice

Notice from Johnny:
Added code tags.

Edited by Johnny (see edit history)

Share this post


Link to post
Share on other sites

Welp, i can tell you why it doesnt work the way you want it to. Reason being, it's impossible to multiply <script>document.write(screen.width); </script> by any number. $width has to equal an integer in order for it to be multiplied, or whatever.

Share this post


Link to post
Share on other sites

truefusion is right. The variable $width is not holding a number but is holding a text string. PHP cannot multiply a text string by two, so it returns 0.

 

After a short time searching on the web I have cobbled together a system that could work, although I have had no time to try it.

 

Create an HTML page with the following code in it:

<html><head></head><body><script>window.location="page.php?height="+screen.height+"&width="+screen.width;</script></body></html>

Then on the page called page.php (feel free to change it in the script above):

<?php$height = $_GET['height'];$width = $_GET['width'];//Now the rest of your page...

In page.php the variables should now hold the screen resolution. If you want to check then just echo those variables and see what you get.

 

Good luck

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.