使用curl从6个列表中向3个随机网站发送信息

时间:2017-02-26 11:57:44

标签: php curl

我有一个邮件,可以将个人广告发送到类似网站的小型网络,但我想更改它,以便将独奏发送到列表中的3个随机网站,而不是全部。我只有非常基本的PHP知识,并花了很多时间尝试解决这个问题并检查论坛。我假设我必须建立一个阵列,但不知道从哪里开始。以下是文件的相关编码:

 <?php

 session_start();

 include "../config.php";
 include "../header.php";
 include "../style.php";
 error_reporting(E_ALL);
 $id = $_POST['id'];

 if($_SESSION['admin'] != $adminpw) {

    ?><table>
    <tr>
    <td width="15%" valign=top><br>
    <? include("adminnavigation.php"); ?>
    </td>
    <td  valign="top" align="center"><br><br> <?
    echo "<font size=2 face='$fonttype' color='$fontcolour'><p><b><center>";



    if($_POST['submit'] == "Delete") {


    foreach($id as $each) {
    mysql_query ("update solos set added=0, approved=0, subject='',  adbody='', url='' where id=".$each);
    }

    echo "<p><center>The solos have been sent back to the users.</p></center>";
    } else {

    error_reporting(E_ALL);

    foreach($id as $each) {
    mysql_query ("update solos set approved=1, date='".time()."' where id=".$each);


    $sql = mysql_query("SELECT * FROM solos WHERE id=".$each);
    $info = mysql_fetch_array($sql);


                    // Work out the data
                     $wannasay = array (
                            "subject" => $info['subject'],
                            "adbody" => $info['adbody'],
                            "userid" => $info['userid'],
                            "url" => $domain."/solo_click.php?id=".$info['id']
                            );
                     $dataels = array();
                     foreach (array_keys($wannasay) as $thiskey) {
                            array_push($dataels,urlencode($thiskey) ."=".
                                            urlencode($wannasay[$thiskey]));
                            }
 $data = implode("&",$dataels);

                    $curl = curl_init();
                    curl_setopt($curl, CURLOPT_URL, "http://www.WEBSITE1.COM/admin/solo_curl.php");
                    curl_setopt($curl, CURLOPT_POST, 1);
                    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
                    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
                    $page = curl_exec($curl);
                    curl_close($curl);

                    $curl = curl_init();
                    curl_setopt($curl, CURLOPT_URL, "http://www.WEBSITE2.com/admin/solo_curl.php");
                    curl_setopt($curl, CURLOPT_POST, 1);
                    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
                    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
                    $page = curl_exec($curl);
                    curl_close($curl);

                    $curl = curl_init();
                    curl_setopt($curl, CURLOPT_URL, "http://www.WEBSITE3.com/admin/solo_curl.php");
                    curl_setopt($curl, CURLOPT_POST, 1);
                    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
                    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
                    $page = curl_exec($curl);
                    curl_close($curl);

                    $curl = curl_init();
                    curl_setopt($curl, CURLOPT_URL, "http://www.WEBSITE4.com/admin/solo_curl.php");
                    curl_setopt($curl, CURLOPT_POST, 1);
                    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
                    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
                    $page = curl_exec($curl);
                    curl_close($curl);

                    $curl = curl_init();
                    curl_setopt($curl, CURLOPT_URL, "http://www.WEBSITE5.com/admin/solo_curl.php");
                    curl_setopt($curl, CURLOPT_POST, 1);
                    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
                    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
                    $page = curl_exec($curl);
                    curl_close($curl);

                    $curl = curl_init();
                    curl_setopt($curl, CURLOPT_URL, "http://www.WEBSITE6.com/admin/solo_curl.php");
                    curl_setopt($curl, CURLOPT_POST, 1);
                    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
                    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
                    $page = curl_exec($curl);
                    curl_close($curl);

这是用于批准管理员中的独奏广告的文件,然后将该信息发送到其他站点的相关文件以放置在数据库中。我希望每次批准个人广告时都会将独立广告发送到3个随机网站,所以实际上只需要编码才能实现这一点。

由于

马丁

1 个答案:

答案 0 :(得分:0)

$data = implode("&",$dataels);之后添加以下内容:

$website_array = array(
    0 => 'website1.com/admin/solo_curl.php',
    1 => 'website2.com/admin/solo_curl.php',
    2 => 'website3.com/admin/solo_curl.php',
    3 => 'website4.com/admin/solo_curl.php',
    4 => 'website5.com/admin/solo_curl.php',
    5 => 'website6.com/admin/solo_curl.php'
);
$rand_keys = array_rand($website_array, 3);
foreach ($rand_keys as $key) {
    $website_to_send_to = $website_array[$key];
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $website_to_send_to);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $page = curl_exec($curl);
    curl_close($curl);
}

并删除所有cURL部分。