在我的简单网络服务中,我想将一些数据发布到用户自定义网址,并重定向到该网址。例如,在我的服务器中使用简单事务后,我必须将一些数据传递给用户redirect_url
,我认为此代码可以发布但我无法重定向到并显示发布的数据
public function redirect_to_customer($result = [], $redirect_url = "")
{
$ch = curl_init($redirect_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $result);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
}
此代码目前无效:
function redirect_to_customer($result = [], $redirect_url = "")
{
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function closethisasap() {
document.forms["redirectpost"].submit();
}
</script>
</head>
<body onload="closethisasap();">
<form name="redirectpost" method="post" action="<? echo $redirect_url; ?>">
<?php
if (!is_null($result)) {
foreach ($result as $k => $v) {
echo '<input type="hidden" name="' . $k . '" value="' . $v . '"> ';
}
}
?>
</form>
</body>
</html>
<?php
}
我在网址上获得html代码,例如:
http://sample.com/%3C!DOCTYPE%20html%3E%3Chtml%3E%20%20%20%20%3Chead%3E%20%20%20%20%20%20%20%20%3Cmeta%20charset=
答案 0 :(得分:0)
你必须首先修复你的第二个函数redirect_to_customer函数并且不要将html代码放在php之外,而是将它分配给某个php变量然后像这样回显它
function redirect_to_customer($result = [], $redirect_url = "")
{
$html = '<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function closethisasap() {
document.forms["redirectpost"].submit();
}
</script>
</head>........';
echo $html;
}
其他服务,html将在其中包括