PHP, Flash Redirection Question

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

mamaluke
Forum Newbie
Posts: 19
Joined: Tue May 16, 2006 1:03 am

PHP, Flash Redirection Question

Post by mamaluke »

Ok, What I'm doing is creating a form in flash where it has 2 textboxs so people can register to my service.

Then what it does is post the code to a text file with php. I have everything working fine the only problem is after they register I want it to redirect them to a thank you page which I'm having problems with

Heres my code so far.


FLASH CODE in SIGNUP.swf (this is in the submit button)

Code: Select all

on (release) {

      loadVariablesNum ("form-send.php", "0", "Post");
		
}
PHP Code in form-send.php

Code: Select all

<?
/*
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

	
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
// write form results to file


$fp = fopen("form-results.txt", "a"); 
fwrite($fp, $_POST[''] . "

-----

Username: " . 
			$_POST['UserName'] . "
Password: " . 
			$_POST['Pass'] . "" . 
			$_POST[''] . "" . 
			$_POST[''] . "" . 
			$_POST[''] . "" . 
			$_POST[''] . "" . 
			$_POST[''] . "
Date:  " . 
			date("M-d-Y") . "\n");
fclose($fp);

?>
Would I put something after the ?> tags in the same php file? Or will that not work can somone please help thanks
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post by bdlang »

Generally speaking, the way to do this is with the header() function.

example:

Code: Select all

if ( form was submitted ) {
    if ( file open successfull ) {
        write file;
        close file;

        // redirect to your 'thank you' page
        header("Location: thankyou.html");

    }
}
Please note that you cannot output anything (not even an errant space) to the browser prior to the call to header().
mamaluke
Forum Newbie
Posts: 19
Joined: Tue May 16, 2006 1:03 am

Post by mamaluke »

So my code would be?

Code: Select all

<!-- PHP easy-form -->
<?
/*
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

	
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
// write form results to file


$fp = fopen("form-results.txt", "a"); 
fwrite($fp, $_POST[''] . "

-----

Username: " . 
			$_POST['UserName'] . "
Password: " . 
			$_POST['Pass'] . "" . 
			$_POST[''] . "" . 
			$_POST[''] . "" . 
			$_POST[''] . "" . 
			$_POST[''] . "" . 
			$_POST[''] . "
Date:  " . 
			date("M-d-Y") . "\n");
fclose($fp);

 // redirect to your 'thank you' page
        header("Location: thankyou.html);

    } 

?>
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post by bdlang »

Well, you have some issues with your script pertaining to you reference to the $_POST superglobal, and you want to watch that closing brace '}' without an opening brace.

I'd strongly recommend validating any values coming from the form (never trust the user) and some logic to test for the form submission and verify the file can be opened, written to.

If I may ask, do you have a specific reason to reference an empty index in the $_POST array, e.g. $_POST['']? Or are those placeholders for data keys you don't want shown on the forum?
mamaluke
Forum Newbie
Posts: 19
Joined: Tue May 16, 2006 1:03 am

Post by mamaluke »

They are just spaces so it looks more organized the text document. Oh yeah and I just tryed that code and what it does is at the bottom of my flash site it says it says its send infromation to ripway.com which my file is on but nothing happens the flash website stays. I mean i am gettin the results in text but i dont know it wont reidirect? Why is the flash staying on the screen
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post by bdlang »

Hmm, my bad. You should have called header() like so, with an absolute URI:

Code: Select all

header("Location: http://yourdomainhere.com/thankyou.html");
Give that a shot. ;)
mamaluke
Forum Newbie
Posts: 19
Joined: Tue May 16, 2006 1:03 am

Post by mamaluke »

Ok, It says its going to my redirection website now at the bottom of the browser but my flash wont go away. It stays up there strong lol. Maybe its time to head to a flash forum? Unless anyone is familler with this problem
mamaluke
Forum Newbie
Posts: 19
Joined: Tue May 16, 2006 1:03 am

Post by mamaluke »

Ok so im guessing no one knows the answer to this? Thanks for the help anyways guys
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

A Flash movie won't obey a header("Location: blah.com"); redirect. You'll need to send a back a variable to your flash movie to indicate whether or not the PHP bit worked, and redirect the user based on that from the Flash. I've not idea what the ActionScript to forward someone to a different page is though.
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post by bdlang »

onion2k wrote:A Flash movie won't obey a header("Location: blah.com"); redirect. You'll need to send a back a variable to your flash movie to indicate whether or not the PHP bit worked, and redirect the user based on that from the Flash. I've not idea what the ActionScript to forward someone to a different page is though.
Ahh, so if the flash calls the form-send.php script, it still has to have some handler to let it know the variables have passed and it can do it's thing...
mamaluke
Forum Newbie
Posts: 19
Joined: Tue May 16, 2006 1:03 am

Post by mamaluke »

I know what the action script would be but what would be the code to send it back to flash? And on flash to recognize that php is trying to tell it to do something?
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Post by aerodromoi »

bdlang wrote: Ahh, so if the flash calls the form-send.php script, it still has to have some handler to let it know the variables have passed and it can do it's thing...
Just echo "&tvar=received&" at the end of the php script. The actionscript below will redirect to http://www.yourtest.com if the variable tvar contains the string "received". You'll probably have to modify the script according to the events on your timeline.

aerodromoi

Actionscript

Code: Select all

onLoad () {
    var backend = "source.php";
    var rvar;
}
onFrame (1) {
    phploader = new LoadVars();
    phploader.onLoad = function(success){
      if (success){
          _root.rvar = this.tvar; 
          gotoandplay(2);
      }
      else{
          rvar = "Error: No Data";    
      }
    };
    phploader.load(backend);
    stop();
}
onFrame (2) {
    if (rvar=="received") {
        getURL("http://www.yourtest.com","_self");
    }
}
onFrame (3) {
    stop();
}
mamaluke
Forum Newbie
Posts: 19
Joined: Tue May 16, 2006 1:03 am

Post by mamaluke »

Ok, Well my flash animation is about 30 seconds long because there is tons of animations going on. I have about 30 different layers so how would I do this? Because im looking at the code and im guessing this would be for a STILL flash movie instead of animated.
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Post by aerodromoi »

mamaluke wrote:Ok, Well my flash animation is about 30 seconds long because there is tons of animations going on. I have about 30 different layers so how would I do this? Because im looking at the code and im guessing this would be for a STILL flash movie instead of animated.
The Flash plugin cares little whether a movie is animated or not - code is code. ;)

If you do want to save yourself some hassle, just put the code somewhere on the timeline (embraced by stop tags), setlabel the section accordingly and create an on (release) {gotoandplay("label");} event.

aerodromoi
mamaluke
Forum Newbie
Posts: 19
Joined: Tue May 16, 2006 1:03 am

Post by mamaluke »

Thanks everyone expecially aerodrom I finally finished what I was going for.


One more question im not sure if you people will be familler with this but what I'm trying to do is make it so when you open up my html file it will redirect a already open window to a different website.

Let me explain. I have a window that is already up which I named "client" so what I need to do is have when the website loads up the website in the window client changes to the new html file i specify autmaticlly without clicking any buttons.

Code: Select all

<a href="newpage.html" target="client">Enter The Hotel</a>
Im guessing that is theh code for when you click a link to change it but is there a way to make it automaticlly change this window when my main html loads up? If you cant help with this thanks alot anyways for the other help!
Post Reply