pentan Posted April 24, 2008 Share Posted April 24, 2008 I couldn't find anything in past posts so apologies if this has been answered before. How can I set up, using PHP alone, a redirect to an outside page with POST variables attached? I've looked at cURL and the header() function and can't find any way to do it. Thanks, Michael Quote Link to comment https://forums.phpfreaks.com/topic/102726-redirect-with-post-variables/ Share on other sites More sharing options...
The Little Guy Posted April 24, 2008 Share Posted April 24, 2008 could you please give an example? Quote Link to comment https://forums.phpfreaks.com/topic/102726-redirect-with-post-variables/#findComment-526025 Share on other sites More sharing options...
947740 Posted April 24, 2008 Share Posted April 24, 2008 Post variables only work on the page right after the form submission. You would have to use sessions to pass the variables along to subsequent pages. Quote Link to comment https://forums.phpfreaks.com/topic/102726-redirect-with-post-variables/#findComment-526029 Share on other sites More sharing options...
ryanhowdy Posted April 24, 2008 Share Posted April 24, 2008 Something like this? if (isset($_POST['your_post_var'])) { echo "<meta http-equiv='refresh' content='0;URL=yahoo.com'>"; } Quote Link to comment https://forums.phpfreaks.com/topic/102726-redirect-with-post-variables/#findComment-526030 Share on other sites More sharing options...
JasonLewis Posted April 24, 2008 Share Posted April 24, 2008 No, you could have an exact replica of the form on the page but make all the fields hidden. Then using javascript and the body's onload you can submit this form whose action is the outside page. Could work. Quote Link to comment https://forums.phpfreaks.com/topic/102726-redirect-with-post-variables/#findComment-526034 Share on other sites More sharing options...
pentan Posted April 24, 2008 Author Share Posted April 24, 2008 I need to avoid sending any of the post data to the browser due to security concerns. So I want to do something like: $var2post="big=ben&tom=jerry"; header( location: "https://www.outsidesitethatidontcontrol.com",$var2post); I'm not seeing any curl function that will redirect after posting the variables to the remote site. Michael Quote Link to comment https://forums.phpfreaks.com/topic/102726-redirect-with-post-variables/#findComment-526086 Share on other sites More sharing options...
haku Posted April 24, 2008 Share Posted April 24, 2008 Use this to redirect to the remote site: header( location: "https://www.outsidesitethatidontcontrol.com" . $var2post); Then on the remote site you can access those variables using $_GET['big'] and $_GET['tom']. Quote Link to comment https://forums.phpfreaks.com/topic/102726-redirect-with-post-variables/#findComment-526223 Share on other sites More sharing options...
The Little Guy Posted April 24, 2008 Share Posted April 24, 2008 you are both wrong, the quotes need to be around the location: too, so it would/could look like this: <?php header( "location: https://www.outsidesitethatidontcontrol.com".$var2post);?> Quote Link to comment https://forums.phpfreaks.com/topic/102726-redirect-with-post-variables/#findComment-526229 Share on other sites More sharing options...
haku Posted April 24, 2008 Share Posted April 24, 2008 My bad, I just copied his code and changed the comma. Quote Link to comment https://forums.phpfreaks.com/topic/102726-redirect-with-post-variables/#findComment-526231 Share on other sites More sharing options...
pentan Posted April 24, 2008 Author Share Posted April 24, 2008 Again, it needs to be POST variables, not GET variables. Michael Quote Link to comment https://forums.phpfreaks.com/topic/102726-redirect-with-post-variables/#findComment-526393 Share on other sites More sharing options...
TecBrat Posted April 24, 2008 Share Posted April 24, 2008 can you not just point the form's action to the offsite page? (unless you need to do something with the values first.) Quote Link to comment https://forums.phpfreaks.com/topic/102726-redirect-with-post-variables/#findComment-526429 Share on other sites More sharing options...
haku Posted April 24, 2008 Share Posted April 24, 2008 I've never tried it, but maybe you could set the action of the form as being the remote address. Other than that, why does it have to be post and not get? Quote Link to comment https://forums.phpfreaks.com/topic/102726-redirect-with-post-variables/#findComment-526675 Share on other sites More sharing options...
DarkWater Posted April 24, 2008 Share Posted April 24, 2008 POST holds more data and is more secure. I think it can be done with cURL. Read up on cURL in the PHP manual. Quote Link to comment https://forums.phpfreaks.com/topic/102726-redirect-with-post-variables/#findComment-526684 Share on other sites More sharing options...
haku Posted April 25, 2008 Share Posted April 25, 2008 Post cannot and should not be considered as secure. While POST is more secure than GET, in that you cannot see the variables in the URL, it's still easily manipulated by someone who knows what they are doing (and those are most likely the people that the OP is attempting to protect against). I still don't see the problem with GET for this situation - send the variables to the remote server using GET, then GET them, process them, and redirect the page so that they are not visible anymore. Quote Link to comment https://forums.phpfreaks.com/topic/102726-redirect-with-post-variables/#findComment-526748 Share on other sites More sharing options...
DarkWater Posted April 25, 2008 Share Posted April 25, 2008 @haku, I know, it's just slightly more secure than GET. I tamper with POST data all the time on sites to see how they work. Rather fun. =) Quote Link to comment https://forums.phpfreaks.com/topic/102726-redirect-with-post-variables/#findComment-526750 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.