1

I'm using Twilio to develop an IVR app and use the [record] tag to take a short recording of someones name.

So page1.php looks something like this:

<?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>

This is fine and the RecordingURL value gets passed into page2.php as it should. However, on page2.php I then ask the user to enter their reference number and need to pass the RecordingURL value into 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");

?>

Any ideas?

1
  • @Dale: Just edit such a mistake, rather than commenting. Jul 25, 2019 at 10:12

2 Answers 2

1

SimonR91 mentioned that he got this to work by building the querystring before the action.

That was the only way that I could find to pass a variable in Twilio also.

However an extra point of clarification is that you cannot use:

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

This causes Twilio to return a busy signal.

Instead you have to $_GET the variable trusting that it is there. Also, you cannot pass the variable directly from Twilio at the beginning of the call. You have to have one script that starts the call and then a second script which can keep passing variables to itself.

0

Try to:

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

Send it as GET, since on page3.php you accept it with GET $rec_url=$_GET['rec_url'];

or try to get it on page3 with post:

$rec_url=$_POST['rec_url'];

edit:
you can try to start sessions on all pages:

<?php start_session(); ?>

and then set it on page2.php like:

 $_SESSION['RecordingUrl']=$rec_url;

then you can have it on page3.php as:

$rec_url=$_SESSION['RecordingUrl'];
2
  • I am definitely receiving the value back in page2.php but get/post does not pass it on the querystring to page3.php
    – srob
    Jul 4, 2013 at 10:14
  • Thanks. I couldn't get the sessions to work but managed to pass it in on the action querystring by building the querystring before the action.
    – srob
    Jul 10, 2013 at 7:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.