PHP script being called by 2 IPs (1 Viewer)

ajetrumpet

Banned
Local time
Yesterday, 23:35
Joined
Jun 22, 2007
Messages
5,638
all,

i have a script that runs when visitors submit a form to me via the website. the script is not perfect, and it certainly can be shortened, but it works fine as is. my ? is...are there any unforseen consequences when two people try to submit the form and call the script at the same time? i had this happen today, and I didn't get the information from one of the form submissions. it's an obvious concern, so i'm looking for a way around it...either that or a better script to send the info to me. here is the relevant portions of the script I run when they push the "submit" button...
PHP:
<?PHP

$to = $_POST["email"];
$subject = "SUBJECT";
$body = "Dear " . $_POST["fname"] . "," . "\r\n" . "\r\n" . "Thank you for...";
$headers = 'From: No-Reply@MYDOMAIN.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $body, $headers);

    // First we set up some parameters for the receiver
    $receiver_name = 'ME';
    $receiver_email = 'corp@MYDOMAIN.com';
    $mydomain = 'MYDOMAIN';

    // This is for the sender's name - NAME OF THE SENDER
    $send_from = $_POST["fname"]. ' ' .$_POST["lname"];

    // This is for the sender's email - EMAIL ADDRESS OF THE SENDER
    $send_from_email = $_POST["email"];

    // This is for the message phone - PHONE NUMBER
    $send_phone = $_POST["phone"];

	//This gives the receiver the SENDER'S NAME and EMAIL ADDRESS	
	$send_header = 'From: ' . $_POST["email"] . "\r\n" . 'Reply-To: ' . 
             $_POST["email"] . "\r\n" . 'X-Mailer: PHP/' . phpversion();
	
	//This gives a sentence requirement if the sender wants the Sequence Builder
	if ($_POST["language"] == "on") {
	
	if ($_POST["prestore"] == "none") {
	$Sentences = "Sentences Requested: " . "\r\n" . "\r\n" . 
             $_POST["S1"] . "\r\n" . $_POST["S2"] . "\r\n" . $_POST["S3"] . 
             "\r\n" . $_POST["S4"] . "\r\n" . $_POST["S5"] . "\r\n" . $_POST["S6"]; }
	else {
		$Sentences = "Sentences Requested: Prestored from US"; }
	
									}
	
	else { $Sentences = ""; }
									 
	$send_title = 'EMAIL FROM: ' . $_POST["fname"] . ' ' .$_POST["lname"];
    $send_body = 'Sender: ' . $send_from . "\r\n" . "\r\n" . 
    'Email: ' . $send_from_email . "\r\n" . "\r\n" . 'Phone: ' . 
    $send_phone . "\r\n" . "\r\n" . 'Operating System: ' . 
    $system . "\r\n" . "\r\n" . 'Access Version: ' . 
    $version . "\r\n" . "\r\n" . 'REQUESTD: ' . 
    $requested . "\r\n" . "\r\n" . $Sentences . 
    "\r\n" . "\r\n" . "\r\n" . "\r\n" . 
    "The following message was sent to: " . 
    $_POST["email"] . "\r\n" . "\r\n" . $body;

    // Now we need to send the message
    $deliver = mail($receiver_email, $send_title, $send_body, $send_header);

   // the PHP mail() function return true if the message was processed so we check.
    if ($deliver == TRUE){ 
		$redirect = "yes";
	} else {
		$redirect = "no";
	}

	// This code will record the order submission in the orders LOG file
	$path = "Logs/REQS.txt";
	
        $s_name = $_POST["fname"] . " " . $_POST["lname"];
		$s_email = $_POST["email"];
		$s_date = date(DATE_COOKIE);
		$Content = $s_name . "|" . $_SERVER['REMOTE_HOST'] . "|" . 
                          $s_date . "|" . $s_email . "  ";

        $fh = @fopen($path,"a");
               fputs($fh,$Content . "\r\n");
        	   fclose ($fh);
	if ($redirect == "yes") {
		header("Location: http://www.MYDOMAIN.com/SUBMISSION.php");
	} else {
		echo '<p>We had a problem sending your request.
             Please e-mail your message directly to us at: ME@MYDOMAIN.com 
             <input name="button" type="button" id="button" 
             onclick=javascript:MM_goToURL("parent","index.php");
             return document.MM_returnValue value="Home" />';
    }

}

?>
 
Last edited:
Local time
Yesterday, 23:35
Joined
Mar 4, 2008
Messages
3,856
I just did a quick google on "make php thread safe" and was surprised at the results.

How I would normally handle this is make a static local variable and set it when starting this "function" and resetting it at the end. Check the static before allowing processing to continue then set it. You'd have to put in some kind of loop if the static is already set and make sure the loop has a way to exit if something goes wrong. Also make sure the loop allows other processing to continue while executing.

Sorry I don't know more about php to help out.
 

Users who are viewing this thread

Top Bottom