0

I am working in PHP zend framework.I have an api function as follows.

http://testmywebsite/API/Testmyapifunction

I have given my api url to one of my client.They had a set up that when they sent a text message my api url is involked.And they are pushing the details of the message such as message content,id,time etc. and i can fetch the details inside my api function.

I fetches the details as in the following way.

$msg_id = $this->_getParam('msg_id');

$msg_senderid = $this->_getParam('msg_senderid');

$msg_content = $this->_getParam('msg_content');

And i am storing these values in my db.Then i want to pass these values to another server.I have the api url of that server.But i cannot pass the values to that server.

I am redirecting the values as in the following way.

$this->_redirect('http://testanotherwebsite/API/Testapifunction.aspx?msg_id='.$msg_id.'&msg_senderid='.$msg_senderid .'&msg_content='.$msg_content);

I want to pass these values to the other server.Anybody please help me.I am working on this issue for many days and its my deadline today.Please help.

Elizabeth Joshy
  • 111
  • 1
  • 1
  • 12
  • Well, did you check that the receiving script accepts these parameters via GET or POST and that you are sending all the required information and that your request even gets sent properly? Besides, using GET, you should probably URI encode your data. Use something like `http_build_query` – Klemen Tusar Feb 02 '15 at 07:37
  • when i test by running the url in address bar of the browser,everything works fine and they can receive the values i passed.The problem is when the process works by sending the text message.We cannot view anything in that case – Elizabeth Joshy Feb 02 '15 at 07:40
  • Can you please show me an example of this 'http_build_query' – Elizabeth Joshy Feb 02 '15 at 07:43
  • Well, as I said, a modern browser will automagically URI encode your data, PHP won't. Do something like this `$this->_redirect('http://testwebsite/API/Testapifunction.aspx?' . http_build_query(array('msg_id' => $msg_id, 'msg_senderid' => $msg_senderid, 'msg_content' => $msg_content)));` More info on `http_build_query` here http://php.net/manual/en/function.http-build-query.php – Klemen Tusar Feb 02 '15 at 07:44
  • I have rewritten the code according to your suggestion,waiting for client to send the message and test,please help me if i have any further clarifications. – Elizabeth Joshy Feb 02 '15 at 08:06
  • Does it work or not? – Klemen Tusar Feb 02 '15 at 08:11
  • i can tell whether it is working, only when client sends a message. – Elizabeth Joshy Feb 02 '15 at 08:15
  • Hii,they have tested,but they are not receiving any values – Elizabeth Joshy Feb 02 '15 at 08:48
  • Does your request even get processed = does your script even make the call? You could try and simply make a `cURL` request and see if that works. – Klemen Tusar Feb 02 '15 at 11:23
  • can you please help me in giving the cURL request? – Elizabeth Joshy Feb 03 '15 at 03:53
  • Can you suggest whether the following is correct or not? $curl = curl_init('http://testwebsite/API/Testapifunction.aspx?msg_id='.$msg_id.'&msg_senderid='.$msg_senderid.'&msg_content='.$msg_content))); curl_setopt($curl, CURLOPT_POSTFIELDS, "foo"); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_exec($curl); – Elizabeth Joshy Feb 03 '15 at 04:04
  • Oh wait, so now you need a `POST` request?! In that case use something like this: http://ur1.ca/jmlxs – Klemen Tusar Feb 03 '15 at 10:50
  • hii,do we need to give the question mark at the end of the url in this case? – Elizabeth Joshy Feb 03 '15 at 11:21
  • No, you don't. It's a `POST` request and you send data in the postfields. – Klemen Tusar Feb 03 '15 at 11:22
  • Sorry,i am getting an error like Call to undefined function curl_init(). I have done the tests in local server – Elizabeth Joshy Feb 03 '15 at 11:54
  • http://stackoverflow.com/questions/6382539/call-to-undefined-function-curl-init – Klemen Tusar Feb 03 '15 at 12:08

1 Answers1

0

I'm not an expert on zend framework, but have read this way:

$this->redirect('/module/controller/action/username/robin/email/robin@example.com');

Also you can try redirector:

$params = array('user' => $user, 'mail' => $mail);
$this->_helper->redirector($action, $controller, $module, $params);

source:

Zend: Redirect to Action with parameters

Community
  • 1
  • 1
manuelbcd
  • 3,106
  • 1
  • 26
  • 39