2

我正在设计的网站的 php 代码运行了两次。这是 bug 的第三天,我的选择已经不多了。

我已经使用错误日志来确认脚本运行了两次。

[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

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

我已经在服务器上测试了其他脚本块,它们没有运行两次(例如电子邮件程序)。奇怪的是,它不是表单提交,甚至不是链接目的地。我直接从不涉及 html 的 url 请求。

这是我的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())。有谁知道如何解决这一问题?如果我没有很快得到答案,我想我会切换到文件创建和另一种通知方式。

编辑编辑

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

4

0 回答 0