I am using a 3rd party sms gateway to send clients a text message when a prospect submits an inquiry form on their web page. I’m using Aweber for the autoresponder system, who sends a query string with the prospect data in it, which I collect and send to the client, along with a text message to his cell phone.
I have everything working. However, I need to prevent the client from receiving multiple text messages from the same prospect within that same session, caused by refreshing or hitting the BACK button on the browser.
Here is the code I’m using, which is working, except for this issue:
$name = $_GET['name'];
$email = $_GET['email'];
$address = $_GET['address'];
$phone = $_GET['phone'];
$phone_sms = preg_replace('/^1|\D/', "", $phone);
$message = "$name, $email, just submitted an inquiry for $address";
$from = "1212121212"; // Ph# txt message is received from
$to = "$phone_sms"; // Ph# txt message is sent to
$url = 'http://domain.com/of/api';
$fields = array(
'from' =>urlencode($from),
'to' =>urlencode($to),
'message' =>urlencode($message),
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
$result = curl_exec($ch);
curl_close($ch);
Thanks much for your help.
If you send a
Locationheader to redirect to a “success” page at the end of the script you posted, the back button will not load the page twice.Try:
Then have
sent.phpshow the confirmation page letting them know their message was sent. If you need to send specific data from their request, add it to a session prior to redirecting and read that data from the session onsent.php.By sending the redirect, the browser will NOT attempt to re-post the same data again when using the back button to navigate. It will also prevent a refresh of the page (after sending the form) from trying to re-post the data again.