I am developing a small script for my minor project and am experiencing some problems.
Let me explain you what I want to do, so that you people can better explain me how to do!!
I have created a form that will submit contents to my sms-gateway provider’s server. And in turn once the server executes the command, it will display an output.
Now the problem is I have made the form and it is submitting everything very properly to the SMS-Gateway provider’s server. But how to gain control back once the server has shown its output. I don’t want my users to see the output shown by the server(and also remain at that very page i.e. http://www.sms-gateway-domain.com/someurlhere), instead I want to echo something more user-friendly based upon the output of the server.
This is my form:-
<form action="http://api.mVaayoo.com/mvaayooapi/MessageCompose?user=[B]email@domain.com[/B]:[B]password[/B]&senderID=Activate&receipientno=<?php echo $mno;?>&msgtxt=Hello,<?php echo '<br>';?>Thank you for registering with us.<?php echo '<br>';?> Your activation code =<?php echo $actcode[0];?>&[B]state=4[/B]" method="post">
<input type="submit" value="Activate Now"/>
</form>
Now when you submit this form an output of this form appears:-
Status=0,ins37_12716948265127
“Status=0 means message was sent successfully, and rest part is id for the message”.If it was status=1 then that would mean something is wrong…
I don’t want to show this kind of message to my users. So please help me!!
Suggest me some method so that I can show my custom message on successfull submission of message.
Thank you very much in advanced!!
Hope this is an easy question and not a tough one. [:)]
well,this is actually what is done if you intregrate for eg paypal in you application
paypal redirects(can be) back to original site after transaction is complete with returning some values…
so check in that API documentation
are there any such features?
other wise
you will submit form to that server…that server wont return back to your server(unless user explicity clicks back button)
so rather than php …the answer lies in features provided by that api
If it really doesnt have any such option…which is very unlikely
i will submit form to my own page use curl to submit form and use the result to decide what to do…
Thank you so much frank1 for replying in such an easy way…
I read there document, it does not contain any information so that the server could bring me back to my page.
It only gives me a cURL example, which is as follows:-
<?php
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, "http://api.mVaayoo.com/mvaayooapi/MessageCompose?user=username:password&senderID=mVaayoo&receipientno=9854521321&msgtxt=This is a test from mVaayoo API&state=4");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "user=$user&senderID=$senderID&receipientno=$receipientno&cid=$cid&msgtxt=$msgtxt");
$buffer = curl_exec($ch);
if(empty ($buffer))
{ echo " buffer is empty "; }
else
{ echo $buffer; }
curl_close($ch);
?>
But to be true, I am very very new to php(read php from book last week) and now I am building my own minor project for submission in college.
The book I used was Kevin Yank’s =‘Build your own website using php and mysql’, which is available from sitepoint itself.
This book didn’t cover anything about cURL and thus I am totally unable to understand this sample code.
Thus, Please guide me on from where to read in detail about cURL and learn about cURL. I want a source which has easy to understand content.
Also if you can explain me all this it would be really great…
ok saw your code again
actually infact you are passing varibales as get to that page
so i guess there is not need for form or curl
you can use file_get_contents
and get the results (may have to process return value if it is not well formatted or not in the exact way in what you want it to be)
have a look at this http://www.phpbuilder.com/board/archive/index.php/t-10316337.html
and give it a try…
it should work…if you cannot make it work
curl is always there
but in typical situation both does the same task (get contents from some where … )
just use that function with some url and may be with your url…
you will know that function
$file="http://api.mVaayoo.com/mvaayooapi/MessageCompose?user=email@domain.com:password&senderID=Activate&receipientno=9898989898&msgtxt=Hello, Thank you for registering with us. Your activation code&state=4";
$result=file_get_contents($file);
echo $result;
But this gives me the following error:-
Warning: file_get_contents(http://...@yahoo.com:msgurway&senderID=Activate&receipientno=9893679398&msgtxt=Hello, Thank you for registering with us. Your activation code&state=4) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 505 HTTP Version Not Supported in C:\wamp\www\Practise\activation\ est.php on line 3
Please give me some suggestion on what does this all means?
I tried to use URL Encode(urlencode()) function to encode the url and I suppose it worked a bit:-
<?php
$file="http://api.mVaayoo.com/mvaayooapi/MessageCompose?user=email@domani.com:password&senderID=Activate&receipientno=9898989898&msgtxt=Hello, Thank you for registering with us. Your activation code&state=4";
echo urlencode($file);
$result=file_get_contents(urlencode($file));
?>
Now there is no error but still it is unable to open stream:-
Warning: file_get_contents(http%3A%2F%2Fapi.mVaayoo.com%2Fmvaayooapi%2FMessageCompose%3Fuser%3Draghav_gupta2003%40yahoo.com%3Amsgmyway%26senderID%3DActivate%26receipientno%3D9893679398%26msgtxt%3DHello%2C+Thank+you+for+registering+with+us.+Your+activation+code%26state%3D4) [function.file-get-contents]: failed to open stream: No error in C:\wamp\www\Practise\activation\ est.php on line 4
i will try to check that…
i am not sure either your url needs that all parameters or not…
any way googling and looking into file_get_contents function will definately help you…
I would like to inform you that, that sms gateway is used by major companies such as yahoo, google etc… in our country and it works with those default settings.
Also I know there is a way to do what I want to do, but its just that I am unable to find it and others are not able to help me on this.
Still I hope frank finds a solution to it soon or else some one else could find an answer…
<?php
$url = "http://api.mVaayoo.com/mvaayooapi/MessageCompose?";
$file="user=email@domani.com:password&senderID=Activate&receipientno=9898989898&msgtxt=Hello, Thank you for registering with us. Your activation code&state=4";
echo urlencode($file);
$result=file_get_contents($url.urlencode($file));
?>
Can some one tell me that how to make my cURL part executable only on button click…
I wrote the code on the page but the page has many more codes written and thus when ever that page is called, cURL part is automatically invoked and a sms is sent… SO I just want that it should be executed only when I press a button…
Please illustrate your answer with sample code, as I am still a learner and understands well with examples
well sorry as i could not take you till end as i was/am very busy with non programming things this week…
I was really planning to look into that thing but i was not able to as i was very busy preparing for one another thing…
any way i think what you mean in last post is
page has
codes that does other things
then curl part
other codes
and when that page is called your curl is also called,
if i got you right then solution can be
<?php
codes
$do_it = ( isset($_GET[‘do_it’]) ) ? (int) $_GET[‘do_it’] : 0;
if ($do_it==1)
{
curl part
}
…
?>
and whenever you need to execute it add &do_it=1 in url
ie page.php?others=1&do_it=1
Ok not secured and can be executed by anyone…(so i think it is public part)