douyouyi8878 2012-02-08 04:34
浏览 16
已采纳

如何构建PHP旋转器

I'm writing a script for a lead contact form that needs to send the first 10 leads to email 1, the second 10 leads to email 2, and so on until it gets to email 4, and then it goes back to email 1.

this is a rotator i have that was built for landing pages, but it rotates 1 each time rather than waiting 10 times, and then rotating. how would I modify this to suit my needs?

Also, it cant happen on every 'refresh' obviously. there would need to be a separate group of code which would go in the action="whatever.php" of the form and thats the code that would increment it.

<?php

//these are the email addresses to be rotated
$email_address[1] = 'email1@email.com';
$email_address[2] = 'email2@email.com';
$email_address[3] = 'email3@email.com';
$email_address[4] = 'email4@email.com';

//this is the text file, which will be stored in the same directory as this file, 
//count.txt needs to be CHMOD to 777, full privileges, to read and write to it.
$myFile = "count.txt";

//open the txt file
$fh = @fopen($myFile, 'r');
$email_number = @fread($fh, 5);
@fclose($fh);

//see which landing page is next in line to be shown.
if ($email_number >= count($email_address)) {
    $email_number = 1;
} else {
    $email_number = $email_number + 1;
}

//write to the txt file.
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $email_number . "
";
fwrite($fh, $stringData);
fclose($fh);

//include the landing page
echo $email_address[$email_number]; 

//terminate script
die();

?>
  • 写回答

1条回答 默认 最新

  • doujianjian2060 2012-02-08 05:12
    关注

    What I understood from your question is there would be form to submit leads and when a lead is submitted, it has to follow your logic. Correct me if I'm wrong.

    If that be the case, use two a text file like track.txt. The initial contents of this text file would be 1,0. Which means leads are sent to first email id 0 times.

    So in the action script of the form include the following code.

    <?php
    $email_address[1] = 'email1@email.com';
    $email_address[2] = 'email2@email.com';
    $email_address[3] = 'email3@email.com';
    $email_address[4] = 'email4@email.com';
    
    $myFile = "track.txt";
    
    //open the txt file
    $fh = @fopen($myFile, 'r');
    $track = @fread($fh, 5);
    @fclose($fh);
    
    $track = explode(",",$track);
    $email = $track[0];
    $count = $track[1];
    
    if($count >= 10)
    {
      $count=0;
      if($email >= count($email_address))
      {
        $email = 1;
      }
      else
      {
        $email++;
      }
    } 
    else
    {
      $count++;
    }
    
    $track = $email.",".$count;
    
    //write to the txt file.
    $fh = fopen($myFile, 'w') or die("can't open file");
    fwrite($fh, $track);
    fclose($fh);
    
    //send lead to $email
    

    ?>

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)