Php代码从url请求运行两次

时间:2013-09-25 17:54:16

标签: php phpmailer

我正在设计的网站的PHP代码运行了两次。这是错误的第三天,我的选项用完了。

我已使用错误日志确认脚本正在运行两次。

[25-Sep-2013 11:18:27] PHP Notice:  renaming. should not see this twice... in /home3/projedc4/public_html/formhandler.php on line 149
[25-Sep-2013 11:18:29] PHP Notice:  renaming. should not see this twice... in /home3/projedc4/public_html/formhandler.php on line 149
[25-Sep-2013 11:18:29] PHP Warning:  rename(/home3/projedc4/public_html/tmparea/3170936.mp3,/home3/projedc4/public_html/uploads/3170936.mp3) [<a href='function.rename'>function.rename</a>]: No such file or directory in /home3/projedc4/public_html/formhandler.php on line 15

(注意:我以前认为这是一个重命名问题,因此我生成了重命名错误。我后来看到它运行了两次,所以我添加了额外的一点,没有看到它两次。而且,行引用是错误的,因为我缩短了代码并删除了机密信息。)

我已在服务器上测试了其他的脚本块,但它们没有运行两次(e.x.Email)。奇怪的是,它不是表单提交甚至是链接目的地。我直接从网址请求,没有涉及到HTML。

这是我的php代码:

<?php
#grab variables
if (($_COOKIE["braceletreg"]) != "") {
    $beattype = "bracelet";
} 
if (($_COOKIE["neckreg1"]) != "") {
    $beattype = "regular necklace clamp";
} 
if (($_COOKIE["neckreg2"]) != "") {
    $beattype = "regular necklace clamp";
} 
if (($_COOKIE["neckjack"]) != "") {
    $beattype = "Headphone jack necklace";
} 
if (($_COOKIE["fwhite"]) != "") {
    $color = "White";
} 
if (($_COOKIE["fblack"]) != "") {
    $color = "black";
} 
if (($_COOKIE["fgreen"]) != "") {
    $color = "green";
} 
if (($_COOKIE["forange"]) != "") {
    $color = "orange";
} 
if (($_COOKIE["stringtype"]) != "") {
    $stringcolor = "Black string";
} 
if (($_COOKIE["stringtype2"]) != "") {
    $stringcolor = "White string";
}
$name = htmlspecialchars($_COOKIE['fname']);
$email = htmlspecialchars($_COOKIE['femail']);
$phone = htmlspecialchars($_COOKIE['fphone']);
$adress = htmlspecialchars($_COOKIE['fadress']);
$customtext = htmlspecialchars($_COOKIE['fcustomtext']);
$number= $_COOKIE['ponum'];

#create dynamic page
function createpage($number,$extention) {
$fh = fopen("uploads/".$number.".html", 'w') or die("can't open file");
fwrite($fh,$number.$extention);
fclose($fh);
echo "file saved";
}

#email content and confirm to user.
function emailsystem($number,$name,$color,$beattype,$phone,$adress,$customtext,$email,$stringcolor,$extention){
include_once('class_phpmailer.php');
    $mail = new PHPMailer();

    $mail->IsSMTP();                                      // set mailer to use SMTP
    $mail->Host = "localhost";  // specify main and backup server
    $mail->From = "order@form.com";
    $mail->FromName = "Your Name";
    $mail->AddAddress("email@thing.com", "Their Name");
    $mail->AddAttachment("uploads/".$number.".".$extention);
    $mail->AddReplyTo("me@mydomain.com", "me");

    $mail->WordWrap = 50;                                 // set word wrap to 50 characters
    $mail->IsHTML(true);                                  // set email format to HTML

    $mail->Subject = "PHPmailer example".$number;
    $mail->Body = "Name: " . $name . "<br>
    color: " . $color . "<br>
    string color: " . $stringcolor . "<br>
    type: " . $beattype . "<br>
    phone: " . $phone . "<br>
    Address: " . $adress . "<br>
    Customtext: " . $customtext . "<br>
    email: " . $email . "<br>
    PO Number".$number."<br>";

    if(!$mail->Send()){
        echo "Message could not be sent. <p>";
        echo "Mailer Error: " . $mail->ErrorInfo;
        exit;
    } else {
        exit;
    }
}
#identify and Move file and create
echo $number."<br>";
if (file_exists("tmparea/" . $number.".mp3") == true) {
    $extention = "mp3";
} else if (file_exists("tmparea/" . $newname.".wav") == true) {
    $extention = "wav";
} else{
    echo "cant get file<br>";
    $extention = "mp3";
}
echo $number.$extention." This is the extention<br>";
trigger_error("renaming. should not see this twice...");
rename('/home3/projedc4/public_html/tmparea/'.$number.'.'.$extention, '/home3/projedc4/public_html/uploads/'.$number.'.'.$extention);
createpage($number,$extention);
emailsystem($number,$name,$color,$beattype,$phone,$adress,$customtext,$email,$stringcolor,$extention);
?>

(我知道我的代码中存在拼写错误等等。没关系。我知道他们在那里并且稍后会清理代码。现在我只需要知道为什么它运行两次以及任何其他编码相关的建议。)

我相信正在进行的是该程序第一次正常运行并通过电子邮件发送给我。然后它再次运行,给我重命名错误(这是通过我的收件箱中的两封带有相同附件的电子邮件确认的。)我不知道为什么。任何帮助将不胜感激......

修改

我正在做一些测试,事实证明,当发送电子邮件时,脚本会运行两次。 (我通过评论$mail->Sent()来解决这个问题。有谁知道如何解决这一问题?如果我很快得不到答案,我想我只会切换到文件创建和另一种通知方式。

编辑编辑

我决定制作一个不依赖电子邮件的系统。它比电子邮件更快,更容易,更友好,但我仍然希望看到这个答案。所以,如果有人有任何想法,请告诉我。

0 个答案:

没有答案