Get X & Y resolution using flash …

3 12 2006

Been a while since i posted anything about flash ( lazy cow moo) heh !

Ever wanted to keep/save information about your site visitors ?
I think its important to keep an eye on visitors resolutions , so when you get to design a website , you’ll know what dimensions you’re going to use . ( including Operating system and IP ).

now lets start with MySQL DataBase , We’ve got several ways to operate & manipulate Mysql DB , either using shell/Command line or simply use PhpMyAdmin

Lets start with creating a database :

CREATE DATABASE `information` ;

Now lets build the table & fields :

CREATE TABLE `resolution` (
`ID` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`X` INT(10) NOT NULL ,
`Y` INT( 10 ) NOT NULL ,
`OS` VARCHAR( 40 ) NOT NULL
) ENGINE = innodb;

Okay enough with mysql , now lets jump to flash & create 2 loadvars() , one to send and one to recieve , then we’ll use System.capabilities object to get the X & Y Resolution and the Operating system running on the visitor machine.
After collecting the information we’ll need to send it to the database using PHP , i’ll show you how ,later in this tutorial .

Flash :

loadObject = new LoadVars();
rcvObject = new LoadVars();
loadObject.Width = System.capabilities.screenResolutionX;;
loadObject.Height = System.capabilities.screenResolutionY;
loadObject.OS = System.capabilities.os;
trace(System.capabilities.os);
//send it
loadObject.sendAndLoad(‘http://www.YourWebSite.com/send.php’,rcvObject);

rcvObject.onLoad = function() {
if(this.Result==’connected’) {
trace(‘inserted’);
}else{
trace(‘wopsy, something went wronge !!’);
}
}

trace(loadObject.Width +’ By ‘ + loadObject.Height + ‘ Using : ‘ + loadObject.OS);

Aight , now lets build the PHP script that will make flash communicate with the database.
It will recieve the loadvars objects and will encapsulate them into php variables :
PHP:

<?php
$host = ‘localhost’;
$user = ‘root’;
$pass = ”;
$db = ‘information’;
$table=’resolutions’;
$Width = $_POST[‘Width’];
$Height = $_POST[‘Height’];
$OS = $_POST[‘OS’];

$DB = mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($db)or die();

$query = “INSERT INTO `resolutions` ( `ID` , `X` , `Y` ,`OS`)
VALUES (
NULL , ‘$Width’, ‘$Height’ , ‘$OS’
)”;

$result = mysql_query($query)or die(mysql_error());

if($result){
echo ‘Result=connected’;
}else{
echo’some went wrong’;
}
?>

you can always add more information ( you will need to add more fields into your database) such as time , referrers & ip ..   e.g:

IP:

$ip = (getenv(HTTP_X_FORWARDED_FOR))
?  getenv(HTTP_X_FORWARDED_FOR)
:  getenv(REMOTE_ADDR);

Referrer: track where you visitors are coming from :

$refer = $_SERVER[‘HTTP_REFERER’];

Time & Date : that will be within the mysql query using mysql function NOW();

$query = “INSERT INTO `resolutions` ( `ID` , `X` , `Y` ,`OS`,`IP`,`time`,`referrer`)

VALUES (NULL , ‘$Width’, ‘$Height’ , ‘$OS’ , ‘$ip’ ,NOW(),’$refer’
)”;

thats it 😀
in case you are wondering how are you going to view the details , you can use the grid component within flash to view them with the help of PHP off course .
something like THIS!

i will show you how to do this on my next tutorial

Advertisements

Actions

Information

7 responses

3 12 2006
G

Thanks Moodyz ;).. I’ll try it on my blog when I get the time.

3 12 2006
G

its applicable on my blog right? (don’t mind me, i’m not really an expert in such stuff :$)

4 12 2006
System.capabilities Flash class example « Cyberspace Nova

[…] Example for getting user resolution and os info from flash can be found on Moodyz Bahrein blog […]

4 12 2006
Mohammed Zainal

*G* :Hey thanks G*shock 😉
i cant tell !! not when you have it hosted @ blogspot , emmmm…
i think you can , you can add the SWF(flash file) embed it into yer blog somewhere and keep the php & database on a different domain …
i hope yer getting what i mean …

5 12 2006
G

So far I’m on the same page as you in terms of understading
all this 🙂

Don’t worry you’ll see me comming back to you if I have any doubts :$

Thanks again dear

1 09 2008
name

Hi!,

1 08 2009
Sandra_Dalene_VanAlstine

Sandra Dalene VanAlstine – Wanted to introduce myself

Thanks
Sandra Dalene VanAlstine

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: