Getting Screen Resolutions

 
Post new topic   Reply to topic    PHP User Group Malta Forum Index // PHP Projects
View previous topic :: View next topic  
Author Message
yancho
Site Admin


Joined: 13 Nov 2007
Posts: 56
Location: Iklin

PostPosted: Fri Nov 23, 2007 9:46 am    Post subject: Getting Screen Resolutions Reply with quote
Guys,

I need to make a script that manages to display an image depending on the screen size!

So I need a make the image displayed depending on the width / height of the resolution.

It has to be a cookie so I keep using it during the whole session.

I found some help if I want to send the data via GET but I just want to either set cookie / POST method.

Thanks
_________________
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger ICQ Number
yancho
Site Admin


Joined: 13 Nov 2007
Posts: 56
Location: Iklin

PostPosted: Fri Nov 23, 2007 11:50 am    Post subject: Reply with quote

 This is the workaround I found .. however if u have a less stupid way I would appreciate it Smile

php:

<?

session_start
();
          
if(isset(
$HTTP_COOKIE_VARS["users_resolution"])) {
    
$screen_res $HTTP_COOKIE_VARS["users_resolution"];
        
setcookie ("width",$HTTP_COOKIE_VARS["width"]);
    
setcookie ("height",$HTTP_COOKIE_VARS["height"]);
}
else 
//means cookie is not found set it using Javascript
{
?>
<script language="javascript">
<!--
writeCookie();

function writeCookie() 
{
 var today = new Date();
 var the_date = new Date("December 31, 9999");
 var the_cookie_date = the_date.toGMTString();
 var the_cookie = "users_resolution="+ screen.width +"x"+ screen.height;
 var the_cookie1 = "width="+ screen.width;
 var the_cookie2 = "height="+ screen.height;
 var the_cookie = the_cookie + ";expires=" + the_cookie_date;
 var the_cookie1 = the_cookie1 + ";expires=" + the_cookie_date;
 var the_cookie2 = the_cookie2 + ";expires=" + the_cookie_date;
 document.cookie=the_cookie;
 document.cookie=the_cookie1;
 document.cookie=the_cookie2;
}
//-->
</script>
<?
}

print_r($_COOKIE);
echo 
"$screen_res";
?>


_________________
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger ICQ Number
hex4



Joined: 13 Nov 2007
Posts: 21
Location: Qormi, Malta

PostPosted: Fri Nov 23, 2007 4:13 pm    Post subject: Reply with quote
i dont think thats a stupid way :p

it's frequently to use javascript between php code

same goes for HTML Smile
_________________
orlandev.com
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
killfr0g



Joined: 13 Nov 2007
Posts: 4
Location: Malta

PostPosted: Mon Nov 26, 2007 5:25 pm    Post subject: Reply with quote
That looks OK but remember JavaScript or cookies may be turned off so it's not 100% reliable. Maybe you can do it using html and css, percentage based..
Back to top
View user's profile Send private message
Christian Sciberras



Joined: 11 Jan 2008
Posts: 8
Location: Malta

PostPosted: Mon Feb 11, 2008 6:09 pm    Post subject: Reply with quote
I agree with killfr0g, percentages should work better.
To do that just use some javascript which changes the image width/height dynamically.
But I suggest using some way to find the best resolution, so that whatever the percentages are, the image still displays nicely.
Or, use some div and span tags to hide some parts of the image, as if it were a java applet but with javascript. You could do that by setting the image as the background and setting the left/top coordinates with javascript.
Whatver the way, good luck!
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
varactor



Joined: 22 Dec 2008
Posts: 10
Location: Malta

PostPosted: Mon Dec 22, 2008 2:00 pm    Post subject: Reply with quote
CSS and HTML is the way to go.

That method ( javascript+ cookies etc ) is good when you need to make calculations based on the users resolution, such as processing some images using GD Library and returning them back to the user.

Also, most of you might know it but I would recommend having a look @ cross-browser dot com
There are loads of very good Screen Resolution functions.

Also, there is a good framework for PHP/JS, called xajax. Take a look at it, its not another yet common ajax library...
Back to top
View user's profile Send private message Visit poster's website
Post new topic   Reply to topic    PHP User Group Malta Forum Index // PHP Projects All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

alexisRed v1.2 // Theme Created By: Andrew Charron and Web Hosting Bluebook // Icons in Part By: Travis Carden
Boards optimised using the phpBB-SEO mod found at phpbb-seo.com
Boards hosted courtesy of solutions-lab.net
Link Backs : PHPClasses.org - MT Page :: PHPUsergroups.org - MT Page



Powered by phpBB © 2001, 2002 phpBB Group