0

I have a couple of links that I need to execute by code:

Here's what it looks like:

http://rest.nexmo.com/sms/xml?api_key=mykey&api_secret=mysec&from=me&to=somenumber&text=test1

I need to do some kind of look which will do it by code:

For example:

Start loop:

execute: 
http://rest.nexmo.com/sms/xml?api_key=mykey&api_secret=mysec&from=me&to=somenumber&text=test1

execute:
http://rest.nexmo.com/sms/xml?api_key=mykey&api_secret=mysec&from=me&to=somenumber&text=test1

end loop

Is this at all possible using php or php/javascript?

7
  • 1
    file_get_contents??? Commented Mar 8, 2014 at 8:28
  • 1
    $i=1;while($i<=2){file_get_contents('http://rest.nexmo.com/sms/xml?api_key=mykey&api_secret=mysec&from=me&to=somenumber&text=test1');$i++;} Commented Mar 8, 2014 at 8:28
  • 1
    with same parameters? &from=me&to=somenumber Commented Mar 8, 2014 at 8:29
  • 1
    set_time_limit(0) to remove time limit Commented Mar 8, 2014 at 8:36
  • 1
    for($i=0; $i<=; $i++) { file_get_contents(ur link); } Commented Mar 8, 2014 at 8:37

1 Answer 1

3
<?php
$ch = curl_init($sub_req_url);
$encoded = '';
// include GET as well as POST variables; your needs may vary.
foreach($_GET as $name => $value) {
  $encoded .= urlencode($name).'='.urlencode($value).'&';
}
foreach($_POST as $name => $value) {
  $encoded .= urlencode($name).'='.urlencode($value).'&';
}
// chop off last ampersand
$encoded = substr($encoded, 0, strlen($encoded)-1);
curl_setopt($ch, CURLOPT_POSTFIELDS,  $encoded);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_exec($ch);
curl_close($ch);
?>

use CURL For execute your Link $sub_req_url = "http://rest.nexmo.com/sms/xml?api_key=mykey&api_secret=mysec&from=me&to=somenumber&text=test1 "

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

1 Comment

here if you want to use GET Or Post Then use curl_setopt($ch, CURLOPT_POSTFIELDS, $encoded); Otherwise remove it and simply call your url.

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.