Include( SWF ) files...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

jclarkkent2003
Forum Contributor
Posts: 123
Joined: Sat Dec 04, 2004 9:14 pm

Include( SWF ) files...

Post by jclarkkent2003 »

Hello all.

I am relatively ok with coding in php, but I am curious at something my old host told me.

He said that I was using alot of server resources when I was "testing" a new script I wrote, and I immediately took it off but I'm wondering if it was really that script or something else.

The script basically, would INCLUDE($X) where $X = http://www.fullurl.com/folders/flash_games_001.swf

So my embed tag for macromedia flash would look like SRC="/game_swf.PHP?gamename=flash_games_001".

This WORKS completely well for SOME games, and not for other games. I'm wondering why and why not, and if there is a better way.

ALSO, VERY important, does this use alot of resources? Does this include, use serious bandwidth or server resources if the swf file is say 2 -5 megabytes. What if I hosted the SWF files on a DIFFERENT SERVER(s) as I do, they are split up on a few different servers.

The game_swf.php is on ONE server with the websites. Would that server INCLUDE the swf from another server and use up bandwidth on the SWF server AND the website server as well or would it just kind of link the swf.

Basically, this scripts' ONLY purpose is to HIDE the location of where the SWF files are hosted, to prevent leeching. I have tried .htaccess to do that, and it works against IFRAMES but does NOT work against the macromedia EMBED swf files and people leech like crazy that way.

Any suggestions and help is VERY much appreciated.

Thank you~!
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

*.swf's are as far as I know downloaded once onto the client and then run, so there is of course bandwidth involved in that, depending on the amount of users you have actually using them. They are however downloaded once, then run on the client, so they are not dynamic in the sence that they need downloading over and over again to stay updated.

Including them from another site, however, might be worse, again depending on amount of visitors.

You script makes your server download the *.swf from a different server (thus using bandwidth to do so) and then again "upload" it to the client wanting to play the game. So in a sence, it is using twice the bandwidth for each file.
jclarkkent2003
Forum Contributor
Posts: 123
Joined: Sat Dec 04, 2004 9:14 pm

Post by jclarkkent2003 »

ok, that is what I was seriously afraid of.

Is there another way you can advise me of to protect against leechers of the swf files. Whatever I can do would be great.

I have the location of the SWF files in EACH game file, so someone plays say game http://www.mydomain.com/bomberman.php and there is a $game_location_url = "http://www.myhostinglocationserver.com/ ... berman.swf" inside the bomberman.php file. I need to know how I can "mask" or disguise this to have it embed or iframe this

http://www.mydomain.com/game_swf.php?game=bomberman.php or something and then it retrieves the $game_location_url and plays the game.

Is there a method of checking the refferer ( i know how to do this already ) and then if correct, it RETURNS the location INSTEAD of including? I don't remember if I tried something like this, but If it returns, it needs to return in the same string format so it can be "embed" in flash or iframe src=""/

I appreciate your and everyone else's help, hopefully I get alot more responses and ideas.

Here's an example of my CURRENT embed.

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shoc ... on=5,0,0,0" width="600" height="400">
<param name="movie" value="http://www.myurl.com/flash-000.swf">
<embed src="http://www.myurl.com/flash-000.swf" width="600" height="400" pluginspage="http://www.macromedia.com/shockwave/dow ... kwaveFlash" type="application/x-shockwave-flash"></embed></object>


I need it to be like this:

<%object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shoc ... on=5,0,0,0" width="600" height="400">
<param name="movie" value="http://www.myurl.com/game_swf.php?game=flash-000">
<%embed src="http://www.myurl.com/game_swf.php?game=flash-000" width="600" height="400" pluginspage="http://www.macromedia.com/shockwave/dow ... kwaveFlash" type="application/x-shockwave-flash"></embed></object>


and my current iframe is this:

<%iframe src="http://www.myurl.com/flash-000.swf"</iframe>

needs to be this:

<%iframe src="http://www.myurl.com/game_swf.php?game= ... "></iframe>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

i dont have time to read this whole thread, so I just skimmed and saw
Is there another way you can advise me of to protect against leechers of the swf files. Whatever I can do would be great.
The best way to protect files is to store them outside your root directly and then have a file which can grab them.

For example, your site directory is:

/user/www/

store the files in /user/files/

and then have a function to grab it like

Code: Select all

function getfile($file)
&#123;
     $root = '/user/files/';

     if (file_exists($root.$file);
     &#123;
          return '/user/files/'.$file;
     &#125;
     else
     &#123;
          return '/user/files/nofile.swf';
     &#125;
&#125;
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Phenom's suggestion is likely the most wanted one. Then you've narrowed down the filetransfer to 50% (!).

There might be ways to stop leechers in the sence of adding a referer-check in the actual *.swf itself. How and if possible, I'm not sure. A question more suitable for the client-side area of this forum I guess.

I'm not sure that embedding the files will stop leeches, as they are still "downloaded" locally (cached) so...
I'm not in liberty to say though... :oops:
jclarkkent2003
Forum Contributor
Posts: 123
Joined: Sat Dec 04, 2004 9:14 pm

Post by jclarkkent2003 »

ok, that method is nearly perfect, except I REALLY do not want the files on the same server as the websites, I have MANY reasons for this, about ten billion reasons, and that's not really up for debate, I'll give one of the biggest reasons (i do not want to change this) is SPACE availible on each server and bandwidth avalible, so can I do that same way by returnning BUT from the remote server?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you should be able to redirect to an "alternate" page which is on the other server, but still provides the loading interface so they don't know the specific file location..

this can be a total redirect, or just writing the swf's url out as being on x server, but through it's download interface none-the-less..

it's basically a load balancing thing.. but via normal outside level servers..
jclarkkent2003
Forum Contributor
Posts: 123
Joined: Sat Dec 04, 2004 9:14 pm

Post by jclarkkent2003 »

ok, like i said, I have more that just one server for hosting these files, in fact I have 11 as of right now and always growing, I have partner ships coming through that is going to add MANY MANY more, possibly into the double or tripple dozens in just a few weeks, but a MAJOR requirement is I have to have leech protection on MY server even though the files are hosted else where.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I never said anything about compromising that.

btw, you can have your server do some communication to the remote server to tell it to expect their call of with unique user key that only works once.
jclarkkent2003
Forum Contributor
Posts: 123
Joined: Sat Dec 04, 2004 9:14 pm

Post by jclarkkent2003 »

ok great, I'm nearly completely clueless on how to do that, aside if I wanted to use mysql I think I could design a way to do that, mysql is WAY too complex that I want this to be, I want this to be pretty much lower server levels like .htaccess and php are PERFECT.

Username and password that are already in the php file would be Absolutely awesome, note, I do not want to have to edit ANY files on the remote servers, while I can login to the 11 currently and change or edit any files I choose, the new servers are most likely going to not be accessable to me since they will be my partners', so I'd like to keep this ALL down to the MAIN website server, all editing and coding will be done on there, and the 11 other servers currently ONLY have .swf files, and that is all.

Can I get some guidance or text alogrithm on how to do something like I need.

I like the idea of daily keys changing INSIDE the game_swf.php file on the MAIN website server, so if anyone does try to copy the game_swf.php?game=flash-000 and use that on their website, I just rotate keys every week or day or even every hour if I wanted to do with cron, so people could leech ONLY from the game_swf.php but they NEVER can see the original file's location ( this is key, I really do not want to have to edit the files location on the remote servers anymore, it is a pain in the butt, I used to change the folder's name every month on the remote servers and then change the path in the website's settings for the folder, this is a good idea but not what I want).

Thanks seriously in advance. Hopefully I can do this for real this time.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

unless you can give them a local swf, and tell it to access the remote data somehow, I don't see how you can avoid not having your server download the file and transmit it back to the user.

The problem is, any remote connection can be seen via certain command line tools... this won't necessarily tell them what program is doing it, or what it's doing.. but it does tell them that there is a connection to that location.

So it may require some database handling on your server to map out the connection to actually go to (so you don't have to tell the swf you pass directly where to go, which shows in the code, if I'm not mistaken)
jclarkkent2003
Forum Contributor
Posts: 123
Joined: Sat Dec 04, 2004 9:14 pm

Post by jclarkkent2003 »

ok, this is what I have so far:

Three Files.

T.php

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shoc ... n=6,0,29,0" width="500" height="500">
<param name="movie" value="test.php"><param name="quality" value="high">
<embed src="test.php" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="500" height="500"></embed></object>


Test.php

<?

function get()
{
return 'test.swf';
}
//$x=get();
$x = include("test.swf");

echo $x;
?>


And the test.swf file (asteroids game).

What happens, When I run t.php, it displays the game PERFECTLY in the embed tags, I play the game, I view source, All I see is test.php is where the game comes from.

now, in test.php, when I visit it via Internet explorer, what I see is a bunch of jumbled code, which is test.swf in ascii code I believe? THIS game is only 20 kb so it was short, but I have games that are as large as 5 mb.

Now, I believe you guys said that this uses TWICE the bandwidth when it is including from a REMOTE location instead of on the same server, since it has to load on the website server FROM the remote location and then again on the client FROM the website server. How else do I do this so it does not use up excessive bandwidth and server resources?

EDIT: and btw, when I uncommented the $x=get(); and commented out the include line, it did NOT work and it just loads REALLY REALLY REALLY REALLY REALLY REALLY slowly, I let it try to load for 5 minutes before stopping, I believe it was looping for some reason.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

if you're able to use my idea of a local swf that you tell it to load x remote file, via it querying your server for the url, then your own server's bandwidth requirements drop insanely, because the download is solely on the user and the remote server sending the data to the given swf.
jclarkkent2003
Forum Contributor
Posts: 123
Joined: Sat Dec 04, 2004 9:14 pm

Post by jclarkkent2003 »

ok,
That sounds perfect, except I haven't the slightest clue on how to do that with flash, honestly I'm a programmer in php, and do not know bs about flash except how to open and close a file, lol.... (I didn't make the games if you were going to ask, and I don't have a flash coder to whip something like that up for me).

It sounds like a VERY short swf however.

The page will be named bomberman.php and has the embed src="local_swf.swf" and the

local_swf.swf needs to (GET no clue on how to do this part, the $game_location var from the bomberman.php which should have been passed down correct?) Then load that swf from that location, btw, some are .dcr and .dir shockwave files, would that require another local_dcr.dcr and what not?

Thanks.

If ANYONE can give me some more help on how to do this, I would be eternally grateful :) I always did want to learn flash, i have the time just don't know where to start.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

might want to hunt down an actionscript programmer.. actionscript.org I think is one.. it's been a while since I've looked at actionscript.
Post Reply