Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

array and curl issue

$
0
0

Hello,

I'm trying to post data to some remote sites and I think
I have something in the wrong order. Any help would be

appreciated.

 

Thanks for your time.

Here is how its suppose to work...

gets array of siteurl from sites

gets the id of the ads being posted (multiple ids)

selects the ad from received

checks to see if the url from the ad (received)
is the same as one of the siteurl in the array

if it is the same then

$url2 should equal $info ['url']

if it is not then $url2 should equal 'http://'.$row['siteurl'].'/ads.php?id='.$info ['id'].'';

Basically it checks to see which site the original ad was posted from
and then when it post back to that site it post the original url, if
it post to a different site then it post a different url.

Right now it post these results


Ad 1

Site 1

http://siteone.com/ads.php?pageid=clickadd&id=1



Site 2

http://sitetwo.com/ads.php?pageid=clickadd&id=1



Site 3

http://sitethree.com/ads.php?pageid=clickadd&id=1



Ad 2

Site 1

http://siteone.com/ads.php?pageid=clickadd&id=2



Site 2

http://sitetwo.com/ads.php?pageid=clickadd&id=2



Site 3

http://sitethree.com/ads.php?pageid=clickadd&id=2





and it should post something like



Ad 1

Site 1

http://siteone.com/ads.php?pageid=clickadd&id=1



Site 2

http://someurl.com // because the ad #1 originally came from site #2



Site 3

http://sitethree.com/ads.php?pageid=clickadd&id=1



Ad 2

Site 1

http://siteone.com/ads.php?pageid=clickadd&id=2



Site 2

http://sitetwo.com/ads.php?pageid=clickadd&id=2



Site 3

http://someotherurl.com // because the ad #2 originally came from site #3
 
 
foreach($id as $each) {



$sql = mysql_query ( "SELECT * FROM receive WHERE id=" . $each );

$info = mysql_fetch_array ( $sql );



        

// Work out partial data , excluding url for checking and updating ...



$wannasay = array (

"id" => $info ['id'],

"site" => $info ['site'];

// Generate Query string

$dataels = array ();

foreach ( array_keys ( $wannasay ) as $thiskey ) {

array_push ( $dataels, urlencode ( $thiskey ) . "=" . urlencode ( $wannasay [$thiskey] ) );

}

$data = implode ( "&", $dataels );





$result = mysql_query("SELECT siteurl FROM sites");

$nodes = array();



$i=0;

while ( $row = mysql_fetch_assoc($result) ) {



  $nodes[] = 'http://'.$row['siteurl'].'/admin/curl.php';

  $nodes2[$i] = $row['siteurl'];

  $i++;





// Here is where I have problems



foreach( $nodes2 as $value )

{



if($value == $info ['site']) {

$url2 = $info ['url'];

} else $url2 =  'http://'.$row['siteurl'].'/ads.php?id='.$info ['id'].'';







}





$postfields = $data.'&url=' . $url2; // Update Full query string ..

$node_count = count($nodes);



$curl_arr = array();

$master = curl_multi_init();



for($i = 0; $i < $node_count; $i++)

{

    $url =$nodes[$i];

    $curl_arr[$i] = curl_init($url);

    curl_setopt($curl_arr[$i], CURLOPT_POST, 1);

    curl_setopt($curl_arr[$i], CURLOPT_POSTFIELDS, $postfields);

    curl_setopt($curl_arr[$i], CURLOPT_RETURNTRANSFER, 1);

    curl_multi_add_handle($master, $curl_arr[$i]);

}



do {

    curl_multi_exec($master,$running);

} while($running > 0);





for($i = 0; $i < $node_count; $i++)

{

    $results = curl_multi_getcontent  ( $curl_arr[$i]  );

    echo( "\n" . $results . "\n");

}



}



}
 

Viewing all articles
Browse latest Browse all 13200

Trending Articles