u:p:
Extreme Support > Support Forums

  TICKET INFORMATION
Ticket Home  >  All Tropo Scripting - PHP Development  >  #1359516 - $session = new Session(); breaks my php scriptSearch
Author/Date
Account Ticket #1359516:  $session = new Session(); breaks my php script
itelecom

Posted on:
2/15/2011 3:45 PM (EST)
$session = new Session();

I am trying to get the session id so that I can have interrupts in things later like to put someone on hold but interrupt them later when someone can take their call, but just doing this:

$session = new Session();

breaks my script.

I don't know why at all...

Here is my entire script right now:

<?php
require_once('tropo.class.php');

$tropo = new Tropo();

$session = new Session();

$tropo->say("You will now be put on hold. Aren't we nice? lol.");


$tropo->say("http://example.com/holdmusic.mp3",array(
    "allowSignals" => "exit"
));

$tropo->RenderJson();


?>

If I comment out $session = new Session(); it works fine, with that there, it dies. I can't for the life of me figure out why. Note: this is running on a php script on my server not hosted by tropo.
kazokanishi

Posted on:
2/15/2011 5:26 PM (EST)
Hello,

What error do you receive if you do not comment out "$session = new Session();"?
Could you please send us the logs?

If we can be of absolutely any further assistance in the meantime,
please do not hesitate to let us know.

Best regards,

Kaz O.
Voxeo Support
Tropo Blog
itelecom

Posted on:
2/15/2011 5:44 PM (EST)
Fatal error: Uncaught exception 'TropoException' with message 'No JSON available.' in /var/www/foxdunes/phonetests/tropo/tropo.class.php:1327 Stack trace: #0 /var/www/foxdunes/phonetests/tropo/holdtests.php(16): Session->__construct() #1 {main} thrown in /var/www/foxdunes/phonetests/tropo/tropo.class.php on line 1327

Is the error I am getting.

Also, when I try to see what is contained in the json myself like this:

$json = file_get_contents("php://input");

then saving the contents of $json to a file it is simply an empty string.

I think somehow the json is not being sent to my script and this is what is causing the error. I've tried the script with error reporting on and off and have tried it on different hosts and I still cannot get any json sent to it.

The error I am getting 'no JSON available' comes from the session class with this code:

$json = file_get_contents("php://input");
// if $json is still empty, there was nothing in
// the POST so throw exception
  if(empty($json)) {
throw new TropoException('No JSON available.', 1);
  }
}

So I am pretty sure that somehow or another the json simply isn't making it to my script and this is why I can do things like make my application speak things, but I cannot do anything that requires the json being sent in the first place like using the session object.

I have even tried the suggestion from this page:
https://www.tropo.com/forums/home.jsp?xt=1297809899195&&bb-cid=99&bb-statusBitToShow=0&bb-tid=1302777#bb

which is to use
@$session = new Session();

This does not work either.
JustinDupree

Posted on:
2/15/2011 6:38 PM (EST)
Hello,

Currently, neither of your applications is set to be WebAPI - they're both Scripting - but your script is written as a WebAPI app.  Try creating a new app, set it as WebAPI, then provide the same URLs and give it another shot.  Let us know if that works out or if you have any further trouble.

Justin Dupree
Voxeo Labs
itelecom

Posted on:
2/16/2011 12:46 PM (EST)
Yes that was it. Thank you.