DoubleDunk
DoubleDunk

Reputation: 939

how to redirect a page from flash using php

Hello community I have the following scenario.

I have a swf with a button that sends a URL request to a php file. Which is the following.

    <?php
      session_start();

      if(isset($_SESSION['user'])){

        header ('Location: http://mydomain.com/test/reroute.php');
        exit();
      }
   ?>

However, the php file does not reroute to the desired page. Am I missing something?

Thank you very much,

Upvotes: 2

Views: 243

Answers (1)

pho
pho

Reputation: 25489

To go to a page from flash, you need to do navigateToURL as follows:

navigateToURL(new URLRequest("http://mydomain.com/test/reroute.php"), "_self");

EDIT To softcode the redirect url, I suggest you do this (I suspect this is more relevant to what you're looking for)

private var loader:URLLoader=new URLLoader();

private function init():void {
    //In the class initialize handler
    loader.addEventListener(Event.COMPLETE, redirectReceived);
}

private function redirectReceived(e:Event):void {
    if(StringUtil.trim(e.target.data).length > 0) {
        navigateToURL(new URLRequest(e.target.data), "_self");
    }
}

private function buttonClick(e:MouseEvent):void {
    loader.load(new URLRequest("http://path_to_the_php_which_tells_you_where_to_redirect"));
}

And the php which tells you where to redirect will be like this:

<?php
      session_start();

      if(isset($_SESSION['user'])){

        echo('Location: http://mydomain.com/test/reroute.php');

      }
?>

Upvotes: 2

Related Questions