View Full Version : I've seen this, would like to know how it's done.
Terikan
05-11-2006, 08:33 PM
A flash file I've come across does a sendandload (you are lookin at a newb here really) to a php file, and the php returns the ip address of the person who loaded the flash into a variable.
Could anyone tell me what I would use for a php script and actionscript to make this happen?
Also need to be able to call the php script from flash files hosted on other domains, and not sure how to allow that.
PHP:
<?php
echo "&ip_address=" . $_SERVER['REMOTE_ADDR'] . "&";
?>
Flash:
var cVar:LoadVars = new LoadVars();
cVar.load('path/to/php/file.php');
cVar.onLoad = function(ret:Boolean):Void {
if(ret) {
trace("User's IP Address: " + this.ip_address);
} else {
// could not load the PHP file
}
}
As for cross domain usage - check, for example, thread: http://www.actionscript.org/forums/showthread.php3?t=105260
hope it helps...
Terikan
05-12-2006, 04:40 AM
Your actionscript code won't publish, keeps saying line 3 { expected. I can't figure it out.
Terikan
05-12-2006, 05:18 AM
Shouldn't this at least display the text "User's IP Address"?
I mean it shows nothing but a blank box when I try it. I removed some of the code to make it publish, so that might be why, but I'm lost here. halp?
CyanBlue
05-12-2006, 10:39 AM
Sx's example is done in ActionScript 2.0 and I think you are publishing for ActionScript 1.0... Try this if it is the case...
var cVar = new LoadVars();
cVar.load('path/to/php/file.php');
cVar.onLoad = function(ret) {
if(ret) {
trace("User's IP Address: " + this.ip_address);
} else {
// could not load the PHP file
}
}Good to see you again, Sx... :)
Terikan
05-12-2006, 04:59 PM
I'm using whatever the default is for flash 8.
Your code publishes, but I still get nothing. Is it possible there's a block on doing this from my php host? Which would be awardspace.com fyi.
If I access the php page directly I get my ip. If I run the swf in the same directory as the php file, I get absolutely nothing, just a blank flash.
Put the absolute path to your .php file on the server, and run it from within Flash Authoring Environment, and then watch what it traces... That should give you an idea what's wrong with it...
Terikan
05-12-2006, 08:15 PM
It shows a blank swf and a popup window that says output and has the following contents.
User's IP Address: " . $_SERVER['REMOTE_ADDR'] . "
Then your PHP doesn't work fine - it byte-loads it, not executing it on the server. Check your hosting provider weither it supports PHP or not.
Terikan
05-12-2006, 09:29 PM
it does. If you load the php address in a browser it reports your ip address.
I also have phpBB2 running on my site.
I'll do some checking, but do you know a free hosting site where I could put a php file like this?
If it works from the browser, copy the exact same address from the browser's address field and put it in the cVar.load(); function... The way it reports it it's definitely because file that gets loaded does not get processed - it's loaded as a raw .txt file.
Terikan
05-12-2006, 10:34 PM
edit: cool it works, not sure what I was doin wrong before but woot!
thanks for all your help guys
Terikan
05-13-2006, 09:04 AM
Another question.
I'm taking the IP and comparing it to a flash var using an if IP = flashvarIP thing.
What I'd like to do now is make it so it will do partial matches, such as only putting the first two sets of numbers in the flashvars, and if the first two sets of the returned IP match, then etc.
Any help with that?
Well, do a .split(".") on the received IP and it will give you an array with all 4 numbers of the IP. Then you can compare each number to your predefined values...
Terikan
05-13-2006, 05:24 PM
That went completely over my head. I get what split does, but I don't know what I would write to make them compare.
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.