0

what i am trying to do is send some data to a url and get a response like "success" that indicates that data is received in codeigniter. Do i need to configure an api in the codeigniter to test that. I tried the following code but not getting the expected result. To mention I am pretty new in codeigniter and php.

controller xmlPost.php

<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');


Class XmlPost extends CI_controller
{

public function index()
{

$this->load->model('xml_model','message');

$this->message->source = "14045" ;
$this->message->dst = "08887654657";
$this->message->msg = "Hi, this is test";
$this->message->url = 'http://localhost/codeigniter1/index.php/receive';

$data = $this->message->Send();

echo $data;
    }
}
?>

and the model is xml_model.php

<?php

Class Xml_model extends CI_Model {

 var $source; //Source address
 var $dst; //Destination
 var $msg; // Message
 var $url;
 var $api_url;


  function __construct() {
    parent::__construct();
   }

  function Send(){

    $this->api_url = 'http://localhost/codeigniter1/index.php/receive';
    $params = $this->source.'&destinationaddr='.$this->dst.'&shortmessage='.urlencode($this->msg).' '.urlencode($this->url).'';

   $post_data = array(
     "sourceaddr" => $params,
    );

    $stream_options = array(
    'http' => array(
       'method'  => 'POST',
    ),
   );

  $context  = stream_context_create($stream_options);
  $response = file_get_contents($this->api_url, null, $context);
  return $response;
        }
      }

      ?>
4
  • you code is not like that what you want. In MVC you need to call a /controller/action/optional_parameters to get data. where is codeigniter1/index.php/receive? Commented Nov 28, 2014 at 9:08
  • receive.php is another controller in another site in thr htdocs directory of my xampp server and the new site is also codeigniter site @Riad Commented Nov 28, 2014 at 9:50
  • what is returned by receive.php ? you can directly call the page and see the output. Commented Nov 28, 2014 at 15:08
  • no the point is consider that receive.php is a controller of another site and when i send some data to receive.php it will do some validation with that data like if the received data is "123" then return a success message as response. And i don't want to use session library and redirect i.e. $this->session->set_flashdata('$my_var' , $data["id"]); redirect('/receive/receive_finction/'); I want to accomplish that @Riad Commented Nov 29, 2014 at 4:23

1 Answer 1

1
After url encoing Space[ ] can encoded as + sign.you have to manually replace as %20,then after execute your URL.
public function sendSMS($mobile,$code)
{

      $stream_options = array(
    'http' => array(
       'method'  => 'GET',
        ),
    );
             $context  = stream_context_create($stream_options);
     $url="http://api.smsbrain.in/1.2/appsms/send.php?user=satish123&passwd=123456&senderId=SATISH&recipients=".$mobile."&message=Your%20Verification%20code%20for%20facebook%20is%20".$code.".";
     //echo "URL".$url;
     $response = file_get_contents($url, null, $context);


    echo print_r($response);

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.