views:

972

answers:

5

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>
A: 
<?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);
?>
Amber
it`s still not working, thanks if you havee any ideeas i would be gragtefull
DanTdr
he requires the script to pass all variables!
dusoft
A: 

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.

John
i do not want an normal redirect.. i want to pass the variables from the form to another website.. the redirect is good but it`s not passing variables
DanTdr
well if the script on the other site doesn't accept get, then your going to have to use cURL to post to it.actually what's this script on the other site and why can't you just put it on your own server/re-code it?
John
print_r($_POST); so you can see what's going on, as recomended by "Dav"
John
A: 

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)

dusoft
Still not working cose the script contains name variables like : variable[name] and because of the "[ ]" the fields are transmitted so i need to somehow redirect the form and the variables without trying to get the values they have.. if it would work it would be great.. or it could help me if you would know how to proecss fields with these names : variable[name] for example the input has the name = " variable[name]"
DanTdr
http_build_query() http://us3.php.net/manual/en/function.http-build-query.php
Adam Backstrom
you need to use ftunction serialize for array variables" serialize(variable);then do unserialize on receiving end
dusoft
A: 
<?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']

John
how is this related to the redirection?
dusoft
it's not, genius. he's trying to do some ninja sh!t with his script because some file he has is on another server that he doesn't have access to - i'm just helping him understand how <input name="key[value]" works so he can solve the overall problem in a more efficent manner.
John
great this seem to work i can now post the data contained into the variable, ket me see if i can do the whole thing.But thanks i realy needed this
DanTdr
ok the script works great from a html form, now i can proccess variables but the flash is still not passing the variables :-? what could i do?
DanTdr
set up a blank php file like this <?php print_r($_POST); ?> and another one with _GET respectively - try posting to a page like that so you can see if the data is actually going through, also make sure you properly using the getURL or as3 equivalent. - right now if your trying to post to that exact script above, it's not going to work unless there is a value for $_POST['key']['yourmom'] - your pretty much there, just make sure your using right command in actionscript to post or get the information and you should be good.
John
A: 

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.

Brent Baisley