screen res from javascript to php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
runelore
Forum Commoner
Posts: 25
Joined: Thu Aug 22, 2002 10:14 am

screen res from javascript to php

Post by runelore »

Hi, I need to find the end users screen resolution for a stats page I am creating. I know this has to be done using javascript. I can use javascript to store a variable with the information. My problem is how do I get that variable into php? (I don't wanna refresh the screen in any way). thank you.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

If you don't want to refresh the page in any way then you can't get that variable from javascript to PHP.

Otherwise, you could store the value in a cookie and then access it later with PHP, or put the value in the URL and access it using $_GET or post it and access it using $_POST. PHP and JavaScript cannot talk to each other directly though since one is server-side and the other client-side.

Mac
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Make a either an inline-frame or a frameset with rows=100%,0. The 0 is the "invisible" frame where you can store data, submit it etc. etc.

So, just create a form in the invisible frame, have the values of the screen-res filled in, then autosubmit. nobody will see it (well...:p )
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Oh yes, or put it in a frame (forgot about that, tend to avoid frames myself) - you do need to refresh something for PHP to get the info though.

Mac
runelore
Forum Commoner
Posts: 25
Joined: Thu Aug 22, 2002 10:14 am

Post by runelore »

Thank you very much, I hadn't thought of that... thanks.
runelore
Forum Commoner
Posts: 25
Joined: Thu Aug 22, 2002 10:14 am

Post by runelore »

is there any way to get the screen res other than javascript. This is because a lot fo the stuff we do is without frames. Thanks...
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Screen-res is client-side. In order for PHP to get that info you need to use one of the options above.

If you use an inline-frame and can be reasonably sure that people will use a browser which understands inline-frames, do that. It won't impact on any search-engine's indexing.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You have to use something client side to get the screen resolution - which is why PHP can't do it but JavaScript can.

Mac
runelore
Forum Commoner
Posts: 25
Joined: Thu Aug 22, 2002 10:14 am

Post by runelore »

Thank you all very much.. I appreciate all your help... thanks again.
Post Reply