开发者

SMS Gateway and API in php

I'm trying to send user credentials via sms after registration.The gateway can be accessed using GET method via HTTP API.So I want to integrate it into my registration_process.php file so that as soon as the details are entered in db the sms should be delivered .

The GET method is similar to

http://gatewayprovider?user=<username>&password=<password>&msg=<$my m开发者_运维问答sg>&no=<$receiver no>

So how can I call this url without any knowledge to the user. That is in a secure manner

Thanks.


You can you cURL, if it is installed and enabled on the webserver.

Slightly modified example from php.net

$url = "http://gatewayprovider?user=".$username."&password=".$password."&msg=".$myMsg."&no=".$receiver_no;

// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);

// grab URL and pass it to the browser
curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);

When you say

That is in a secure manner

I can hardly believe sending the data in cleartext as a http GET request is safe.

The data will be invisble for the user, but anyone sniffing your data can read it. Does the gateway provide https?

Also sending data using GET, opposed to POST method is not really safe, since the request url will be visible in the logs, thinking of firewalls and so on. This is of course on the route from your server to the sms gateway.

If you SMS Gateway supports it, POST+HTTPS would be the best choice. cURL would also be an ideal choice to use here.

In case you dont have cUrl installed, you can use wget, by calling a shell script.


There are numerous ways to make an HTTP request from PHP. cURL is a popular one.


you can also use

<?php
$url = "http://gatewayprovider?user=<username>&password=<password>&msg=<$my msg>&no=<$receiver no>";
$sendrequest = file_get_contents($url);
?>

That's it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜