csplrj Posted June 1, 2007 Share Posted June 1, 2007 How to forward a page to another page alongwith the parameters passed into it I mean I have page a.php which is called with some parameters in $_POST and I require to pass these to another page with same variables in $_POST Please Help for the same Thanks in advance CSJakharia Quote Link to comment https://forums.phpfreaks.com/topic/53850-forward-to-page-alongwith-variables-in-post/ Share on other sites More sharing options...
Dragen Posted June 1, 2007 Share Posted June 1, 2007 just use a form with the post attribute. set all of the $_POST variables as hidden inputs with the same name as the $_POST[]. something like: echo '<input type="hidden" name="NAME OF VARIABLE HERE" value="' . $_POST['NAME OF VARIABLE HERE'] . '" />'; Quote Link to comment https://forums.phpfreaks.com/topic/53850-forward-to-page-alongwith-variables-in-post/#findComment-266196 Share on other sites More sharing options...
MemphiS Posted June 1, 2007 Share Posted June 1, 2007 <form action='b.php' method='post'> any variables you set on a.php will be posted to b.php im assuming that what your looking for.. Quote Link to comment https://forums.phpfreaks.com/topic/53850-forward-to-page-alongwith-variables-in-post/#findComment-266197 Share on other sites More sharing options...
chigley Posted June 1, 2007 Share Posted June 1, 2007 a.php (this file has already received some post variables) <?php echo "<form action=\"b.php\" method=\"post\">\n"; foreach($_POST as $k => $v) { echo " <input type=\"hidden\" name=\"$k\" value=\"$v\" />\n"; } // Output the rest of your form here ?> Quote Link to comment https://forums.phpfreaks.com/topic/53850-forward-to-page-alongwith-variables-in-post/#findComment-266200 Share on other sites More sharing options...
csplrj Posted June 1, 2007 Author Share Posted June 1, 2007 No The whole scenorio is ab.html has all the elements it has form tag with action to a.php a.php later requires to forward the variables in the $_POST to b.php as POST only I hope now you got my question i do not require to show another form in a.php but it will forward the controls to b.php Thanks in advance CSJakharia Quote Link to comment https://forums.phpfreaks.com/topic/53850-forward-to-page-alongwith-variables-in-post/#findComment-266221 Share on other sites More sharing options...
chigley Posted June 1, 2007 Share Posted June 1, 2007 You'd have to use cURL, which is pretty stupid. Why not set each of the post variables on a.php as a session variable, redirect to b.php and load the session variables there? Quote Link to comment https://forums.phpfreaks.com/topic/53850-forward-to-page-alongwith-variables-in-post/#findComment-266226 Share on other sites More sharing options...
Dragen Posted June 1, 2007 Share Posted June 1, 2007 I think chigley's got your answer there. Sounds the best idea for what you need Quote Link to comment https://forums.phpfreaks.com/topic/53850-forward-to-page-alongwith-variables-in-post/#findComment-266235 Share on other sites More sharing options...
csplrj Posted June 1, 2007 Author Share Posted June 1, 2007 Thanks But I thought if there was some better way out as In JSP we can forward the control to other page without browser being acknowledged about it,So I thought if PHP has some such sort of functionality Thanks in advance CSJakharia Quote Link to comment https://forums.phpfreaks.com/topic/53850-forward-to-page-alongwith-variables-in-post/#findComment-266266 Share on other sites More sharing options...
Dragen Posted June 1, 2007 Share Posted June 1, 2007 why go to all the trouble when you cold easily use a form or sessions? with sessions the user wouldn't have to have any interaction to carry the variables across, it would just happen. Quote Link to comment https://forums.phpfreaks.com/topic/53850-forward-to-page-alongwith-variables-in-post/#findComment-266281 Share on other sites More sharing options...
per1os Posted June 1, 2007 Share Posted June 1, 2007 You want sessions man www.php.net/session www.php.net/session_start Remember that session_start(); has to be at the top of a.php and b.php before ANY output is sent to the screen. a.php <?php session_start(); // register post as session vars foreach ($_POST as $key => $val) { $_SESSION[$key] = $val; } // goto b.php somehow echo '<a href=b.php>Goto B.php</a>'; ?> b.php <?php session_start(); // viola the variables are passed to b.php without the user ever knowing. echo '<pre>',print_r($_SESSION),'</pre>'; // thanks to chigley for pointing out that mistake. ?> Quote Link to comment https://forums.phpfreaks.com/topic/53850-forward-to-page-alongwith-variables-in-post/#findComment-266290 Share on other sites More sharing options...
chigley Posted June 1, 2007 Share Posted June 1, 2007 I don't think: echo '<pre>',$_SESSION,'</pre>' Will work... will it? I've always used: echo "<pre>".print_r($_SESSION,true)."</pre>"; Quote Link to comment https://forums.phpfreaks.com/topic/53850-forward-to-page-alongwith-variables-in-post/#findComment-266292 Share on other sites More sharing options...
per1os Posted June 1, 2007 Share Posted June 1, 2007 No it won't, just a typo on my part. Note edited the code I posted to reflect the correct way to print out an array =) Quote Link to comment https://forums.phpfreaks.com/topic/53850-forward-to-page-alongwith-variables-in-post/#findComment-266294 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.