Retrieve a PHP value


Retrieve a PHP value

我正在使用Twilio开发一个IVR应用程序,并使用[记录]标记来记录某人的名字。

所以page1.php看起来像这样:

<?php
    header("content-type: text/xml");
    echo "<?xml version='"1.0'" encoding='"UTF-8'"?>'n";
?>
<Response>
     <Say>Please state your name after the tone</Say>
     <Record maxLength="20" finishOnKey="#" playBeep="true" action="page2.php" />
</Response>

这很好,RecordingURL值会按原样传递到page2.php中。然而,在page2.php上,我要求用户输入他们的参考号,并需要将RecordingURL值传递到page3.php.中

Page2.php

<?php   
header("content-type: text/xml");
echo "<?xml version='"1.0'" encoding='"UTF-8'"?>'n";
$rec_url=$_REQUEST['RecordingUrl'];
?>
<Response>
<Gather timeout="7" finishOnKey="#" numDigits="3" action="page3.php?rec_url=<?php echo   $_REQUEST['RecordingUrl']; ?>" method="POST">
<Say>Please now enter your reference number</Say>
</Gather>
</Response>

Page3.php

<?php 
header("content-type: text/xml");
echo "<?xml version='"1.0'" encoding='"UTF-8'"?>'n";
$ref_no=$_REQUEST['Digits'];
$cli=$_REQUEST['From'];  
$rec_url=$_GET['rec_url'];
$nodialled=$_REQUEST['To'];
?>
<Response>
<Say>Thank you. Goodbye.</Say>
</Response>
<?php
$ref_no=$_POST['Digits'];
$cli=$_POST['From'];  
$recording_url=$_POST['rec_url'];
$nodialled=$_POST['To'];
$html="<br />";
file_put_contents("test.html", "CLI: $cli $html Number Dialled: $nodialled $html   Reference: $ref_no $html Recording URL: $recording_url");
?>

有什么想法吗?

SimonR91提到,他通过在操作之前构建查询字符串来实现这一点。

这也是我在Twilio中传递变量的唯一方法。

然而,需要说明的一点是,您不能使用:

if (isset $_GET["variable"])
{
  $variable = $_GET["variable"];
}

这导致Twilio返回繁忙信号。

相反,您必须$_GET变量,相信它在那里。此外,您不能在调用开始时直接从Twilio传递变量。您必须有一个脚本来启动调用,然后有第二个脚本可以不断地将变量传递给自己。

尝试:

<Gather timeout="7" finishOnKey="#" numDigits="3" action="page3.php?rec_url=<?php echo $_REQUEST['RecordingUrl']; ?>"

将其作为GET发送,因为在page3.php上,您使用GET $rec_url=$_GET['rec_url']; 接受它

或者尝试在第3页上发布:

$rec_url=$_POST['rec_url'];

编辑
您可以尝试在所有页面上启动会话:

<?php start_session(); ?>

然后将其设置在page2.php上,如:

 $_SESSION['RecordingUrl']=$rec_url;

然后你可以把它放在page3.php上作为:

$rec_url=$_SESSION['RecordingUrl'];