简体   繁体   中英

Redirect back to own webpage after visiting another website

I want to send sms through my php page.

My SMS Gateway provider has given my api like
" http://sms.xyz.com/uname=abc&pass=xyz&phone=1234567890&msg=hello "
(visiting this url in browser sends an sms to the phone number)

I want my script to just visit this url (so that the sms is sent) and return to my own page (irrespective of the result) and print "Message sent"

Please suggest any way to do this.

Make use of cURL

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://sms.xyz.com/uname=abc&pass=xyz&phone=1234567890&msg=hello");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // For HTTPS
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // For HTTPS
curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); // Returns 200 if everything went well
if($statusCode==200)
{
echo "<script>alert('SMS Sent');</script>";
echo "<script>document.location.href='welcome.html'</script>"; //Redirecting back after successfully sent SMS
}
else
{ 
echo "<script>alert('SMS Sending Failed.');</script>";
}

curl_close($ch);

Guess youre looking for "location" in JavaScript.

http://www.w3schools.com/js/js_window_location.asp

You can't redirect back to your page unless the API specifically allows it and has something like a returnURL variable.

Have a look at cURL in PHP. It will send the request to the other webpage without displaying the page in the browser. That way you keep the user on your page and don't need to redirect them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM