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




Variables … Why they write/type them this way anyway ?

24 11 2006

variables

Been doing a lil reasearch about variables naming and naming space in programming language , i finally found what i was looking for , a good article about variables naming convention… thought I’d share :

In computer programming, a naming convention is a set of rules for choosing the character sequence to be used for identifiers in source code and documentation.

Reasons for using a naming convention (as opposed to allowing programmers to choose any character sequence) include the following:

  • to make source code easier to read and understand with less effort;
  • to enhance source code appearance (for example, by disallowing overly long names or abbreviations);

The choice of naming conventions can be an enormously controversial issue, with partisans of each holding theirs to be the best and others to be inferior.

ReadMore >>