Question

Hey here is my problem : i made a flash and i can`t change it no mather what. That flash had a form that was sending data to my subdomain.. i had to remove the subdomain and i got a new website, the problem is this : how do i redirect the form data from the old site to the new one? In the flash i had the form send the data to : subdomain.site.ro/subscribe.php i still have that file there and i could write a script in it but the field names are something like : field[name] and i can't process them so i must send them to the original script witch is now on another site : othersite.ro/subscribe.php.

So basicaly i must write a script that passes the post/get variables to the new script (on the new website) or to write a .htaccess file that will redirect the post/get variables to the new website

Can someone help me? i`ve been searching for a long time and i could not find anything helpfull I would be gratefull if you would at least try to help. Thanks, Dan

Ok Now i can proccess the variables with the script below(with a html form). But the flash is not sending any variables to the script. i tried a lot of things and i am still trying.. any ideeas ? if yes please let me know. Thanks, Dan

<?php
if(isset($_POST['key']['yourmom'])) 
echo 'Your mom is '.$_POST['key']['yourmom'].' and your face '.$_POST['key']['yourface'];
?>


<form method="post">
<input type="hidden" name="key[yourmom]" value="lol">
<input type="hidden" name="key[yourface]" value="failed">
<input type="submit">
</form>
Was it helpful?

Solution

<?php
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: http://othersite.ro/subscribe.php");
    header("Connection: close");

    exit;
?>

If that doesn't accomplish what you need, then you might try resorting to acting as somewhat of a proxy via curl:

<?php
    $ch = curl_init('http://othersite.ro/subscribe.php');
    curl_setopt ($ch, CURLOPT_POST, 1);
    curl_setopt ($ch, CURLOPT_POSTFIELDS, "key1=val1&key2=val2&key3=val3");
    curl_exec ($ch);
    curl_close ($ch);
?>

OTHER TIPS

yup "Dav" answered that correctly.

also, if you get an error saying headers have already been sent just put "ob_start();" right under the opening "<?php" - that is, if you plan on putting this knee deep in another php script.

you need to loop over the $_POST and $_GET variables (arrays) to get all the variables:

<?php
    header("HTTP/1.1 301 Moved Permanently");
    $poststring="";
    foreach ($_POST as $variable=>$value)
            {
            $poststring.=$variable."=".$value."&";
            }
    header("Location: http://othersite.ro/subscribe.php?".$poststring);
    header("Connection: close");

    exit;
?>

same goes for GET variables (just use $_GET in the same manner)

<?php

    if(isset($_POST['key']['yourmom'])) echo 'Your mom is '.$_POST['key']['yourmom'].' and your face '.$_POST['key']['yourface'];

?>


<form method="post">
<input type="hidden" name="key[yourmom]" value="lol">
<input type="hidden" name="key[yourface]" value="failed">
<input type="submit">
</form>

copy the code above and run it.. instead of $_POST['value'] it's just $_POST['key']['value']

so like <input name='something' = $_POST['something'] is the same as <input name='key[bla]' = $_POST['key']['bla']

The correct way to do it would be to change the DNS record so your old subdomain points to your new one. Then everything just gets submitted to the new domain, although with the same path. But it doesn't sound like you can do that.

The alternative is to emulate the POST that the your flash app submitted using curl. Just grab the url query string (GETs) and submit the POST. It doesn't matter that your field names are $_POST['key']['value'].

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'othersite.ro/subscribe.php?'.$_SERVER['QUERY_STRING']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
curl_setopt($ch, CURLOPT_USERAGENT, 'Redirect Fix');
$result = curl_exec($ch);
curl_close($ch);

You could even return the $result variable to your flash app. Then you just have a server in the middle routing data back and forth. You can drop the CURLOPT_USERAGENT line, you just use that if you want to specify a custom agent, normally this is the browser identifier string.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top