PHP + Flash

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

pureDesi
Forum Newbie
Posts: 10
Joined: Thu Aug 10, 2006 11:46 am

PHP + Flash

Post 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.
Mijanur
Forum Newbie
Posts: 10
Joined: Wed Aug 02, 2006 8:23 am

chmod error

Post by Mijanur »

try changing the CHMOD permissions
pureDesi
Forum Newbie
Posts: 10
Joined: Thu Aug 10, 2006 11:46 am

Post by pureDesi »

What would I change them to?
I tried 640, 600, but I can still access them via browser.
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

Files are typically 644 and directories are 755. But it may depend on what you are doing with the PHP file.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Specifically, what is the error you get from the web server?
pureDesi
Forum Newbie
Posts: 10
Joined: Thu Aug 10, 2006 11:46 am

Post 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?
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post 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.
pureDesi
Forum Newbie
Posts: 10
Joined: Thu Aug 10, 2006 11:46 am

Post 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 :/
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post 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....
pureDesi
Forum Newbie
Posts: 10
Joined: Thu Aug 10, 2006 11:46 am

Post by pureDesi »

That's not a bad idea, I think i'll do that. thanks, appreciate it.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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");
}
?>
pureDesi
Forum Newbie
Posts: 10
Joined: Thu Aug 10, 2006 11:46 am

Post 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:
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Was I wrong then? Hmmm
How does PHP work with Flash then?
pureDesi
Forum Newbie
Posts: 10
Joined: Thu Aug 10, 2006 11:46 am

Post 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.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
Post Reply