curl_setopt help

Discussion in 'PHP' started by Dablue, Jan 19, 2010.

  1. #1
    hi,

    im making a script so that i can submit articles to all of my site at once i have got so far but i dont know how to post it...

    the form that is on the the sites is a post not get so i dont know how to do it...

    i have a foreach site in array to do this..

       
     curl_setopt ($ch, CURLOPT_URL, $url);
        curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
        curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
        curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt ($ch, CURLOPT_REFERER, 'http://www.google.com/');
        $AskApache_result = curl_exec ($ch);
    
    PHP:
    but i dont know how to get it to submit...

    what it needs to do is for me to fill out a form (for the article) then when i submit, it needs to look up the sites i want to post to (in the form before post) then go to the url(in the with in the script and post the information to the url) then echo that it has posted it to that site...

    if anyone could help i will return the favour.
     
    Dablue, Jan 19, 2010 IP
  2. Sky AK47

    Sky AK47 Member

    Messages:
    298
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    45
    #2
    Use CURLOPT_POST and CURLOPT_POSTFIELDS, check the php manual or google how to use them properly.
     
    Sky AK47, Jan 19, 2010 IP
  3. Dablue

    Dablue Active Member

    Messages:
    132
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #3
    I have tried that but it is still not working..
     
    Dablue, Jan 19, 2010 IP
  4. Sky AK47

    Sky AK47 Member

    Messages:
    298
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    45
    #4
    What have you tried exactly? can you post please.
     
    Sky AK47, Jan 19, 2010 IP
  5. Dablue

    Dablue Active Member

    Messages:
    132
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #5
    im trying this on another script at the moment... here it is:
    
    <?
    
    
    if($_POST)
    {
    
    $domains = explode("\n", $_POST[domains]);
    
    
    
    // initialise Curl
    $data = array('ACTION' => 'ADD', 'config' => 'calendar.cfg', 'Month' => '1' , 'Date' => '9' , 'annual' => '1' , 'heading' => '1' );
    $data1 = "ACTION=ADD&config=calendar.cfg&Month=1&Date=9&annual=1&heading=1";
    foreach($domains as $domain)
    {
    
    
    $ch = curl_init();
    
    
        curl_setopt ($ch, CURLOPT_URL, $domain);
        curl_setopt($ch, CURLOPT_POST, 1);
    	curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
        curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt ($ch, CURLOPT_REFERER, 'http://www.google.com/');
        $AskApache_result = curl_exec ($ch);
    
        $regex = '/<title>(.+?)<\/title>/';
        preg_match($regex,$AskApache_result,$output);
        echo $output[1] . '<br>';
        flush();
        ob_flush();
    
    
        if(preg_match('/ENTRY ADDED/', $AskApache_result))
        {
            echo $domain . ' - Pinged!<br>';
        }
        else
        {
            echo $domain . ' - <b>Pinging Failed!</b><br>';
        }
        
        flush();
        ob_flush();
    
    }
    } else {
    ?>
    <form method="post">
    Links:<br>
    <textarea name="domains" cols=100 rows=30></textarea><br>
    <br>
    <input type="submit">
    </table>
    </form>
    
    <?
    }
    ?>
    
    PHP:
     
    Dablue, Jan 19, 2010 IP
  6. szalinski

    szalinski Peon

    Messages:
    341
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    try

    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
    PHP:
     
    szalinski, Jan 19, 2010 IP