I am running the following code, and it is showing me this error. Can someone tell me why is my xml giving a problem? When i run this in the browser I get:
XML Parsing Error: junk after document element
When I run this through Twiilio I get the following error
parserMessage Error on line 2 of document : Content is not allowed in prolog.
<?php
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
";
require "twilio-php-latest/Services/Twilio.php";
/* Set our AccountSid and AuthToken */
$AccountSid = "xxxxx";
$AuthToken = "xxxx";
include 'db.php';
$caller=$_REQUEST['From'];
/* Instantiate a new Twilio Rest Client */
$client = new Services_Twilio($AccountSid, $AuthToken);
$from= "+17864310795";
$student_number=substr($caller,1);
$db = new PDO("mysql:host=localhost;dbname=xxxx","xxxx","xxxx");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$studentData=getSingleStudentData($db,$student_number);
foreach($studentData as $key=>$val)
{
$student_id=$val['student_id'];
$phone=$val['phone_number'];
$status=$val['status'];
echo $student_id;
// find out last call successfully completed by the student
if($status==1)
{
$progress = getLastActivity($db,$student_id);
X
X
X
echo "done with initialize<br/>";
$server= "http://sample.com";
try {
$to = '+' . $phone;
echo $phone;
$questions_id_url='questions_id_0='.$questions_id[0].'&questions_id_1='.$questions_id[1].'&questions_id_2='.$questions_id[2];
$questions_file_url='questions_file_0='.$questions_file[0].'&questions_file_1='.$questions_file[1].'&questions_file_2='.$questions_file[2];
$url = $server.'/startCall.php?call_id='.$call_id.'&phone='.$phone.'&'.$questions_id_url.'&'.$questions_file_url.'&student_id='.$student_id.'&story='
.$story.'&story_id='.$story_id.'&call_number='.$call_number.'&question_number=0&count_english=0&count_hindi=0&insert_receivecall=0';
echo "here"."-----".$url;
$client->account->calls->create(
"+17864310795",
$to,
$url,
array(
'Method' => "GET",
'FallbackMethod' => "GET",
'StatusCallbackMethod' => "GET",
'Record' => "false",
));
} catch (Exception $e) {
// log error
}
}
}
?>
<Response>
<Reject reason="busy"/>
</Response>
I have tried everything, and was hoping I could spot the error
Twilio developer evangelist here.
I think your problem is that you're pushing out more than just XML within that script. You start by setting the content type to XML and echo
ing the XML declaration, but after that you start to echo
what looks like debugging commands, which aren't valid XML, so the parser throws an error.
So, to start, I would comment out or remove anything that echo
s non XML content from your script.
Let me know if that helps.