Apache2Triad Help, Support and Development Forum Index Search Profile Log in to check your private messages Log in Register Memberlist Attachments Statistics Crew/Ranks Archive
 [PHP] resending post data to another page
Google
Post new topic Reply to topic
Author Message
Joshua Meadows (DemoRic)
support
support


Joined: 29 Dec 2004
Posts: 783
Location: S.E. Kansas

PostPosted: Fri Nov 17, 2006 11:09 pm Reply with quoteBack to top

I am having difficulty trying to do this. I have some swf files that try to incorrectly post to a php file at the root of my server instead of a diiferent location.

I have tried using mod_rewrite, but found this removes post data.
I have getting the post data using php's input to put in a form to resubmit to the proper php page, but the data makes the post data too long. I have tried passing $_POST, but that doesn't work.

I want the data flow like this.
swf -> post -> wrongphp -> post -> rightphp

Any suggestions?
Code:

//  Fugly stuff to show people because some autoarcade games don't work
$referer = $_SERVER['HTTP_REFERER'];

ECHO "<META HTTP-EQUIV=\"Refresh\"
      CONTENT=\"15; URL=$referer\">What are you doing here? You shouldn't be here! <i>(Well maybe this is a bug we need to fix.)</i><br /> Redirecting you back to where you came from in <b><i>15</i></b> seconds.  Have fun playing those flash games.  We HOPE to fix this soon<br />\n";
ECHO "<b>Redirect you to $referer </b><br /><hr />";

$rawPostData = file_get_contents('php://input'); // done!

if ($_POST) {
       $postdata = file_get_contents('php://input');
     
       $uglybugger = '/(?<=&)([^&=]+)(?:=([^&]*))/';
       $matches = array();

       preg_match_all($uglybugger, $postdata, $matches);

       $_POST = array();

       $match_count = count($matches[0]);
       for ($i = 0; $i < $match_count; $i++) {
               if (!isset($_POST[$matches[1][$i]])) {
                       $_POST[$matches[1][$i]] = array();
               }
               $_POST[$matches[1][$i]][] = $matches[2][$i];
       }
       $match_count = count($_POST);
       for ($i = 0; $i < $match_count; $i++) {
               if (count($_POST[$i]) == 1) {
                       $_POST[$i] = $_POST[$i][0];
               }
       }
}

//ECHO "<br />$rawPostData<br />";
//ECHO " <button type=\"button\" class=\"button\" onClick=\"window.location='/e107_plugins/autogallery/proarcade.php?".$postdata."['\">Try to Manually Submit Score</button></form></div>";

//ECHO "<button type=\"submit\" class=\"button\" action=\"/e107_plugins/autogallery/proarcade.php\" value=\"$postdata\"onClick=\"window.location='/e107_plugins/autogallery/proarcade.php\">".FMP_PLAY."</button>";

ECHO "Post: $_POST <br />";
foreach ($_POST as $tempString ) {
   ECHO $tempString."<br />\n";
   $completePost = $completePost+$tempString;
}

ECHO "GET:$_GET <br />";
foreach ($_GET as $tempString ) {
   ECHO $tempString."<br />\n";
}


ECHO "Query: $getQuery<br />";
// End Fugly stuff to show people because some autoarcade games don't work

require_once(dirname(__FILE__)."/e107_plugins/autogallery/def.php");

if (!isset($_POST['score'])) exit;
$points = $_POST['score'];

AutoGal_AddScoreViaReferer($points);
View user's profileSend private messageYahoo MessengerICQ Number
cigraphics
 
 


Joined: 21 Aug 2005
Posts: 148
Location: Romania, Pitesti

PostPosted: Tue Nov 21, 2006 11:39 am Reply with quoteBack to top

try to put in the wrongphp another form like this
Code:

<form action="rightphp" method="post">
<input type="hidden" name="name" value="<?=$_POST['what'];?>"/>
<input type="hidden" name="name2" value="<?=$_POST['what2'];?>"/>
<input type="submit" name="go" value="Submit" />
</form>


or with $_GET[]
then modify the method and you must change $_POST[] to $_GET[]
View user's profileSend private messageSend e-mailYahoo Messenger
Joshua Meadows (DemoRic)
support
support


Joined: 29 Dec 2004
Posts: 783
Location: S.E. Kansas

PostPosted: Wed Nov 22, 2006 12:57 am Reply with quoteBack to top

Hey thanks Cigraphics. I also had coded 2 solutions since I posted here. (the first was essentially what you suggested)

The first creates a submit button that re-posts the $_post contents.
Quote:
$referer = $_SERVER['HTTP_REFERER'];
ECHO "<FORM action=\"/pathto/correct.php\" method=\"post\">";
foreach ($_POST as $key => $value) {
ECHO "<input type=\"hidden\" name=\"$key\" value=\"$value\">";
//$$key = addslashes(trim($value));
}
ECHO "<input type=\"submit\" value=\"Submit Score\"></form>";


The other method essentially lies to the browser to tell it the file has temporarily moved.

Quote:
header("HTTP/1.0 307 Temporary Redirect");//Temporary Redirect Page.
$uri="/pathto/correct.php";
header( "Location: http" .
( isset($_SERVER['REQUEST_URI']) ? $uri .
( $_SERVER['QUERY_STRING'] ? "?" . $_SERVER
['QUERY_STRING'] : "" ) : "" ) );


The thing I found out after doing all of it was that it is a sessions issue, which I still haven't resolved. (Oh, well I've got some new php scripts for my coding toolbox.)
Anyways, Thanks for the reply. Smile
View user's profileSend private messageYahoo MessengerICQ Number
Display posts from previous:      
Post new topic Reply to topic


 Jump to:   



View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum
Powered by phpBB © 2001, 2002 phpBB Group :: FI Theme
All times are GMT