ive just run into a problem. I am sending mail after the form is submitted. I dont want the mail to be sent more than once so i redirect on the same page with setting $_SESSION that controls it. It all worked fine but there is still one problem. Ive just recently found out, that some users cant wait those 5-10 seconds till the email is sent. They click on X in the web browser (I mean the left top X that you can click on while the page is loading something to stop it) and try to send the form again. And when they do this the mail can be sent more than once, because the redirect is not firing up imidiately, just after the mail is sent. Is there any way to do this in one php file or do i have to redirect on the second php file where the email is sent then?
Here is the code :
session_start();
require_once('conne387s1.php');
$today = date('Y-m-d H:i:s');
if(isset($_SESSION['vozidlo']) && !isset($_SESSION['repeat'])){
$_SESSION['repeat'] = true;
$select = "SELECT * FROM vozidla WHERE ID = ".$_SESSION['vozidlo'];
$vozidlo = mysql_fetch_array(mysql_query($select));
$spz = $_SESSION['SPZ'];
$update = "UPDATE vozidla SET SPZ = '".$spz."', CISLO_OSVEDCENIA = '".$_SESSION["CISLO_OSVEDCENIA"]."' WHERE ID = ".$_SESSION['vozidlo'];
mysql_query($update) or die(mysql_error());
// $update = "UPDATE zmluvy SET DOHLASIL_SPZ = '".$today."' WHERE CHECK_ID = '".$_SESSION['chid']."'";
// mysql_query($update) or die(mysql_error());
$select = "SELECT * FROM zmluvy WHERE CHECK_ID = '".$_SESSION['chid']."'";
$zmluva = mysql_fetch_array(mysql_query($select));
$dotaz = "SELECT * FROM `poistnici` WHERE `ID` = ".$zmluva["DRZITEL"];
$vysl = MySQL_Query($dotaz);
$drzitel = mysql_fetch_array($vysl);
$natypoval = '';
if (isset($_SESSION["pred_ID7425"])){
$natypoval = $_SESSION["pred_ID7425"];
} else {
//test ci je to zdielany klient
if (!empty($_SERVER['HTTP_CLIENT_IP'])){
$natypoval=$_SERVER['HTTP_CLIENT_IP'];
//je to proxy adresa
}elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
$natypoval=$_SERVER['HTTP_X_FORWARDED_FOR'];
}else{
$natypoval=$_SERVER['REMOTE_ADDR'];
}
// prehodenie na int z IP
$natypoval = ip2long($natypoval);
}
$spz_zmena = false;
if($vozidlo['SPZ'] != $spz){
$spz_zmena = true;
$insert = "INSERT INTO `kasko_zmluvy_zmeny` (`ID_ZML`,`TIME`,`VYKONAL`,`ZMENA`,`PZP`)
VALUES(".$zmluva["ID"].",'".date('Y-m-d H:i:s', time())."',".$natypoval.",'".mysql_real_escape_string('Zmena EČV '.$vozidlo['SPZ'].'->'.$spz)."',1)"; // vykonal - 0 - system rychlepoistneie s.r.o
MySQL_Query($insert) or die(mysql_error());
}
if($vozidlo['CISLO_OSVEDCENIA'] != $_SESSION['CISLO_OSVEDCENIA']){
$insert = "INSERT INTO `kasko_zmluvy_zmeny` (`ID_ZML`,`TIME`,`VYKONAL`,`ZMENA`,`PZP`)
VALUES(".$zmluva["ID"].",'".date('Y-m-d H:i:s', time())."',".$natypoval.",'".mysql_real_escape_string('Zmena čísla TP '.$vozidlo['CISLO_OSVEDCENIA'].'->'.$_SESSION['CISLO_OSVEDCENIA'])."',1)"; // vykonal - 0 - system rychlepoistneie s.r.o
MySQL_Query($insert) or die(mysql_error());
}
$id_zmluva = $zmluva['ID'];
$id_insur = $zmluva['POISTOVNA'];
$path = getcwd();
$file_name_bk = $path."/predajca/output/temp/Biela_karta_".$zmluva["CISLO_ZMLUVY"];
$file_name2 = $file_name_bk;
$vystup = 'F';
$dohlasovanie = true;
require_once("fpdf/fpdf.php");
require_once("fpdi/fpdi.php");
if($zmluva['POISTOVNA'] == 23){
require("biela_karta_genertel.php");
} else {
require("biela_karta.php");
}
if (isset($_SESSION["pred_ID7425"])){
$vykonal = $_SESSION["pred_ID7425"];
} else {
//test ci je to zdielany klient
if (!empty($_SERVER['HTTP_CLIENT_IP'])){
$vykonal=$_SERVER['HTTP_CLIENT_IP'];
//je to proxy adresa
}elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
$vykonal=$_SERVER['HTTP_X_FORWARDED_FOR'];
}else{
$vykonal=$_SERVER['REMOTE_ADDR'];
}
// prehodenie na int z IP
$vykonal = ip2long($vykonal);
}
require_once("mail/class.phpmailer.php");
require_once("sendMailServer.php");
require_once('../temp_output/crn/reminder_povinne.php');
$mass_mail = new reminder_povinne(6);
$mass_mail->sendBielaKarta(mysql_query($select),$file_name_bk.".pdf", $vykonal);
if($zmluva['EXPORT'] != NULL && $zmluva['EXPORT'] != '000-00-00 00:00:00'){
$mass_mail = new reminder_povinne(7);
$mass_mail->sendDoplneniePoistovna(mysql_query($select),$spz_zmena);
}
session_destroy();
require_once("env1.html");
require_once("env1_1.html");
require_once("env2.html");
echo '</div><div class="article-content"><h1>Ďakujeme za doplnenie údajov k zmluve.</h1><h2> Na Váš e-mail bolo zaslané nové potvrdenie o poistení (biela karta) s doplnenými údajmi.</h2></div>';
require_once("env3.html");
require_once("env4.html");
}
if(isset($_POST['psc']) && !empty($_POST['psc'])){
$_POST['comp60'] = preg_replace("/[^A-Za-z0-9]/", '', $_POST['comp60']);
$err = array();
if (strlen($_POST["comp60"]) == 0)
$err[] = "60|"."„EČV nemôže byť prázdne. Pokiaľ EČV nie je pridelené, alebo sa bude meniť, zvoľte možnosť „zatiaľ nepridelené/EČV sa bude meniť.“";
else if (strlen($_POST["comp60"]) != 5 && strlen($_POST["comp60"]) != 0)
$err[] = "60|"."Nesprávny formát ŠPZ (XX000XX)";
if (strlen($_POST["comp61"]) != 8) $err[] = "61|"."Nesprávne zadaný údaj séria a číslo Osvedčenia o evidencii vozidla.";
$spz = $_POST['psc'].$_POST['comp60'];
$_SESSION['SPZ'] = $spz;
$_SESSION['CISLO_OSVEDCENIA'] = $_POST["comp61"];
if (count($err) < 1){
$_SESSION['vozidlo'] = $_POST['vozidlo'];
$_SESSION['chid'] = $_POST['chid'];
header('Location: dohlasit_spz.php');
// header('Location: kone.php');
return;
}
}
As i said the problem is that the redirection fires up after the email is sent and i dont know why. Please help me I am really desperate.
EDIT: I need to redirect onto the same page and then execute the mail function. Otherwise the client has time to click on the X on web browser (I mean the left top X that you can click on while the page is loading something to stop it) and resend the form. Is there any way to do this in one php file? Because as it is now the mail function fires first ...