To get the viewport size, you must use Javascript, yes.
For examples of code doing that (not always easy, there are differences between browsers), you can take a look at how JS Frameworks/Libraries determine that size (for instance, in prototype.js, there is a getDimensions function that does what you want) ; google will get you lots of results about that too (this one is an example of those results)
Sonra, PHP bu boyutu göndermeniz gerekir. Bunun için, iki çözüm:
- Bir (parametre olarak genişlik ve yüksekliğini gönderme) Ajax isteği kullanmaktır
- The other is to dynamically build an
<img>
tag, with an URL pointing to the PHP script, like 'http://.../size.php?w=WIDTH&h=HEIGHT'
- Birçok istatistik yazılım (Xiti / google analytics gibi şeyler - emin değilim bu olanlar ^ ^ yaparsanız) yönteminin bu tür kullanın.
İkinci durumda, JS kodu bu gibi görünebilir:
<script type="text/javascript">
var width = 100;
var height = 80;
var tag = document.createElement('img'); // Create the tag
tag.src = 'http://tests/temp/viewport/size.php?';
tag.src += 'w=' + width; // Pass the size
tag.src += '&h=' + height;
document.body.appendChild(tag); // Insert the tag into the page
</script>
And then, in size.php, you use $_GET['w'] and $_GET['h'].
Note : you will probably have to return some valid image data from size.php, to not get a "red cross" picture (a transparent gif, 1x1 in size, for instance, will do the trick)