Search code examples
phppostgetrequesttwilio

Retrieve a PHP value


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?


Solution

  • 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'];