Benjamin Oats Benjamin Oats - 8 days ago 5
PHP Question

codeignigter use rest to pass data to external site

OK in plain PHP I use the following to pass data to a GET

file_get_contents('https://ws.mysite.com/some.svc/here?userID=' . $session_id . '&score=' . $percentilescore . '&assessmentID=' . $testID . '&assessmentTitle=some');


I now want to apply this same piece of code to my CI project.

This Is how I have tried.

private function getResults()
{

$score = $this->actions->getSentEmailCount();
$percentilescore = $percentile = $this->actions->getPercentile($score);
$testID = '134';
$percentile = $this->actions->getPercentile($score);
$time = $this->input->get('time');
$timemath = 60000;
$timeinmseconds = $time * $timemath;



$adddata = array(
'uniID' => '5',
'testName' => 'some',
'testID' => $testID,
'total' => '10',
'correct' => $score = $this->actions->getScore(),
'percent' => $score = $this->actions->getScore(),
'dateTaken' => date('Y-m-d H:i:s'),
'timeSpent' => $timeinmseconds,
'userID' => $session_id,
);

$this->actions->add_record($adddata);
return $this->load->view('client/results', $data);

file_get_contents('https://ws.mysite.com/123.svc/some?userID=' . $session_id . '&score=' . $percentilescore . '&assessmentID=' . $testID . '&assessmentTitle=some');

}


It is not posting the data any idea why and how I should do it in CI ?

Answer

return should be the last statement in the function because it's immediately ends execution of the current function. Just put file_get_contents before return:

file_get_contents('https://ws.mysite.com/123.svc/some?userID=' . $session_id . '&score=' . $percentilescore . '&assessmentID=' . $testID . '&assessmentTitle=some');

$this->actions->add_record($adddata);
return $this->load->view('client/results', $data);