Page 1 of 2

PHP + Flash

Posted: Thu Aug 10, 2006 12:04 pm
by pureDesi
I'm currently making a website entirely out of flash with php for the backend, and I'm fairly new to PHP. Is there any way to tell if a PHP document is being accessed by a flash file to verify if I can pass on the information?

Say flash has to access the file register.php, and it should be able to do so with no problems, however when you go to register.php in your browser, it'll display a message saying you cannot access this page.

Any ideas?

Thanks in advance.

chmod error

Posted: Thu Aug 10, 2006 12:20 pm
by Mijanur
try changing the CHMOD permissions

Posted: Thu Aug 10, 2006 7:15 pm
by pureDesi
What would I change them to?
I tried 640, 600, but I can still access them via browser.

Posted: Thu Aug 10, 2006 7:17 pm
by neophyte
Files are typically 644 and directories are 755. But it may depend on what you are doing with the PHP file.

Posted: Thu Aug 10, 2006 7:17 pm
by Ollie Saunders
Specifically, what is the error you get from the web server?

Posted: Thu Aug 10, 2006 7:26 pm
by pureDesi
ole wrote:Specifically, what is the error you get from the web server?
There is no error, I think i might have been misunderstood. I have a flash (.swf) file that reads data from a PHP file. I want that flash object to be the only thing able to access the PHP file. So when they go to site.com/register.php it'll say access denied, but allows flash to access it. I don't think I can do this with CHMODS, I was thinking more along the lines of a function in php that tells what is accessing the file, I know there is the $_SERVER['http_user_agent'] but that returns the browser, I wanted something that returns something along the lines of "Flash" or "ActiveX". Any ideas?

Posted: Thu Aug 10, 2006 7:41 pm
by Ollie Saunders
There is no error, I think i might have been misunderstood.
Yes sorry.
I have a flash (.swf) file that reads data from a PHP file.
Well I don't think that is going to work even if you could get the permissions sorted. The way I understand it, and I may be wrong about this, is that PHP is only executed when requested via the webserver by means of an apache mod or CGI. If you try to access it any other way you will just get source code; its still just a file after all not a binary. For this reason you cannot use flash to execute PHP and get a response. So instead what is done is to request some PHP via a browser and have that generate flash output. Again, I could be wrong, I've no experience of flash with PHP.

Posted: Thu Aug 10, 2006 7:58 pm
by pureDesi
On the contrary it does work with flash, I just need to find out if it's flash that is accessing it. Well, thanks for the help though, I guess I'll have to figure something out :/

Posted: Thu Aug 10, 2006 8:04 pm
by neophyte
Here's a work around. Make a large string key/token to pass between your action script and your PHP script. So both sides have the key. Using Flash's sendAndRecieve method to pass data, pass the key back and forth. The all you need is a simple if statement in both scripts. It'll work. I use a similar method in a Flash movie I created to stop the movie from playing off server. If it's not playing playing in the browser on my server no play....

Posted: Fri Aug 11, 2006 1:10 am
by pureDesi
That's not a bad idea, I think i'll do that. thanks, appreciate it.

Posted: Fri Aug 11, 2006 1:17 am
by RobertGonzalez
That is a similar procedure to keeping unwanted scripts from calling your other included scripts. In the calling script (say index.php), I add in a constant, then in the included file, I check if that constant is defined. If so, continue with the script. If not, die.

index.php

Code: Select all

<?php
define('IN_SCRIPT', true);

include 'include.php';
?>
include.php

Code: Select all

<?php
if ( !defined('IN_SCRIPT') )
{
    die("You are so not authorized to use this page");
}
?>

Posted: Fri Aug 11, 2006 2:32 am
by pureDesi
Thanks for the help, I just implemented it and it works just how I wanted to. There are still some potential security issues, but that's what I get for using flash :roll:

Posted: Fri Aug 11, 2006 3:41 am
by Ollie Saunders
Was I wrong then? Hmmm
How does PHP work with Flash then?

Posted: Fri Aug 11, 2006 4:02 am
by pureDesi
Well, you can call a php file from within flash using a variety of different methods (sendAndReceive, loadVariables, loadVars) . And flash reads it after it's been translated by PHP.

Posted: Fri Aug 11, 2006 4:04 am
by JayBird
ole wrote:Was I wrong then? Hmmm
How does PHP work with Flash then?
Same way as PHP always works. Flash movies sends request for PHP file....server parses it and returns it