PHP重定向到带有一些数据的自定义url
在我的简单Web服务中,我想将一些数据发布到用户自定义url,并重定向到该url。例如,在我的服务器中使用简单事务后,我必须将一些数据传递给用户PHP重定向到带有一些数据的自定义url,php,Php,在我的简单Web服务中,我想将一些数据发布到用户自定义url,并重定向到该url。例如,在我的服务器中使用简单事务后,我必须将一些数据传递给用户重定向\u url,我认为这些代码可以发布,但我不能重定向到并显示发布的数据 public function redirect_to_customer($result = [], $redirect_url = "") { $ch = curl_init($redirect_url); curl_setopt($ch, CURLOPT_P
重定向\u 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
}
您必须首先修复第二个函数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;
}
函数将_重定向到_客户($result=[],$redirect_url=”“)
{
$html='1
函数closethisaap(){
document.forms[“redirectpost”].submit();
}
........';
echo$html;
}
另外,html将在包含的地方输出,您必须首先修复第二个函数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;
}
函数将_重定向到_客户($result=[],$redirect_url=”“)
{
$html='1
函数closethisaap(){
document.forms[“redirectpost”].submit();
}
........';
echo$html;
}
html将在其包含的位置输出的其他设备