Hi all,
I want to get the ip-address of the visitors (or a way to have a count on visitors) I'm thinking about saving to an XML and keep count - simply put!
can you help?
ForumNewbie
10-10-2005, 07:07 PM
Hi,
I spent weeks trying to do the same when trying to track user activity on the darts game. eg. If a user's connectivity dropped briefly, it was supposed to reconnect using the IP address to identify the user. If I remember right, you can't get the IP address from within Flash, or even javascript on the webpage. I had to use server side scripting.
In a nutshell, I discovered it was harder than it ought to be ! Personally, I would use a free tracker like http://www.freewebcounter.com . It's not perfect, but much easier than doing it yourself !
If you are intent on doing this you could try something like the following, which did work in the end:
Set up a PHP server.
Set up a mySQL database with a table called 'usertrack' in a database called 'usertrack'. Set up 5 text fields in it for the _ip, _date, _time, _host, and the _page viewed. Imagine for this example that the mySQL database has a user ID of 'user' and a password of 'password'.
Create a variable in your swf for _page which identifies what page the user is viewing.
Have your swf call a PHP script with this code in it:
<?php
$_page = $_POST['_page'];
$_ip="$REMOTE_ADDR";
$_host=gethostbyaddr($_ip);
if ($_page == null)
{
$_page="$HTTP_REFERER";
}
$_date= date("Ymd");
$_time= date("His");
$dbconnection=@mysql_connect("localhost","user","password");
echo ($dbconnection);
if (!$dbconnection)
{
echo("No SQL SERVER AVAILABLE");
exit();
}
mysql_select_db("usertrack",$dbconnection);
if (! @mysql_select_db("usertrack") )
{
echo( "NO DATABASE AVAILABLE" );
exit();
}
$page="index";
$sql="insert into usertrack values ('$_ip', '$_date', '$_time', '$_page', '$_host')";
echo ($sql);
if ( mysql_query($sql) );
{
echo("<P>Update affected " . mysql_affected_rows() . " rows.</P>");
}
?>
The problem is that if the PHP server is behind a proxy server, the IP address reported is that of the proxy server and not the client, so you then have to modify the proxy server to pass the client IP address instead. Search on the net for something called a 'webresponsemodifier' for how to get round this.
I'm sure there are other ways, but this worked for me. If you prefer using PHP to write an XML file instead of to populate a database, or if you can translate this to an ASP script writing to XML, this may be better for your needs.
Best of luck.
Morgan
Thanks for the reply, I'm going to use freewebcounter!
ForumNewbie
10-10-2005, 08:41 PM
Probably wise !
I was tearing my hair out whilst doing it myself. There's probably an easy way, but I never found what it was.
I've just written up a semi-tutorial on how this can be done using mySQL and PHP in another thread. Hopefully it will spare somebody some pain ! :yikes:
Morgan