ErebosGames
ErebosGames

Reputation: 21

AS3 - Call a PHP script on my server to determine the URL of the SWF

I'm a flash game developer. I need to be able to determine the URL of the page that the SWF is embedded on, and I can't use ExternalInterface. The reason is that a lot of flash portals set allowScriptAccess="never". It's also quite common for flash portals to not actually host the SWF themselves, but embed the SWF on their page and have it loaded from someone else's server. I need a reliable way to determine the URL of the page that the SWF is embedded on, and I can use an external server.

I know this isn't possible using flash alone, but I believe it should be possible in combination with using an external server.

While searching, I came across a forum post that said "Figured it out: Server can get page adress (when browser request file server can read page adress) and return it as param to flash." Unfortunately, no further details were provided. That thread can be found here:

http://www.actionscript.org/forums/showthread.php3?t=138370

I'm not even sure if PHP is what I'm looking for - I have little knowledge of web technologies outside of Flash. My questions are:

  1. Is this actually possible?
  2. If so, what should I use to do it? Is PHP what I'm looking for? Something else?

Update: My goal (however it can be achieved) is to get the URL that the SWF is being viewed on WITHOUT being dependent on any particular embed settings (so no ExternalInterface, or passing in a FlashVar). I won't have control over how and where the SWF is embedded. Exmaple, the SWF is hosted on somedomain.com/test.swf, and it's embedded on fungames.com/cool-game. I need to know that the URL is fungames.com/cool-game. Knowing where the actual SWF file is hosted is not useful information. If the full URL is not obtainable, the domain would be good enough.

Update 2: I got setup with AMFPHP on my server, and I got it to return the HTTP_REFERER, but in my test case, it returned the URL of the SWF and not the URL of the page that the SWF is embedded on. Is there a different property I can look at?

Upvotes: 1

Views: 765

Answers (2)

Ronnie
Ronnie

Reputation: 11198

your swf can call the php page on your server and reference the $_SERVER['HTTP_REFERER'] property

Upvotes: 0

francis
francis

Reputation: 6349

You can get the URL of a running SWF by using this:

var url:String = LoaderInfo(root.loaderInfo).url;

Upvotes: 1

Related Questions