PHP将vars发布给第三方 [英] PHP Post vars to third party
问题描述
我正在尝试在php中获取一些变量,并将用户重定向到第三方站点,并将变量作为后变量发送.我知道使用Cookie可能会更容易,但是已经设置了第三方来处理帖子.有人对如何执行此操作有任何建议吗?
I'm trying to take some variables in php and redirect the user to a third party site with the variables sent as post vars. I know this would probably be easier with cookies but the third party is already set up to handle posts. Does anyone have any suggestions on how to do this?
推荐答案
您可以使用两种技术.一种是遍历POST变量,然后添加到表单中,然后也许使用Javascript onLoad重新提交表单.
There are a couple techniques you could use. One is iterate through the POST vars and add to a form and resubmit the form perhaps using Javascript onLoad.
<html>
<body onload="document.forms[0].submit()">
<form action="new-location.php" method="post">
<?php foreach( $_POST as $key => $val ): ?>
<input type="hidden" name="<?php echo htmlSpecialChars( $key, ENT_COMPAT, 'UTF-8' ) ?>" value="<?php echo htmlSpecialChars( $val, ENT_COMPAT, 'UTF-8' ) ?>">
<?php endforeach; ?>
</form>
</body>
</html>
另一种选择是使用PHP和cURL并将数据发送到远程站点:
Another option would be to use PHP and cURL and send the data to the remote site:
url_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
http://www.php.net/manual/zh/function.curl-setopt.php
这篇关于PHP将vars发布给第三方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!