Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Trouble using cURL in PHP

  • 20-01-2011 11:43am
    #1
    Registered Users, Registered Users 2 Posts: 19,048 ✭✭✭✭


    Hi all,
    I've been asked to upload a new game our company has made to a load of free flash game sites. I don't fancy doing this by hand (about 200 hundred sites!) so I'm trying (so far without much success) to use cURL as all these sites use the same type of HTML form. An example of one such upload page would be: http://www.arcade101.com/submit/form.html

    I've tried following 2 tutorials here and here but neither approach has worked for me.

    I've tried to break it down and just submit to a single form, before moving on to automate it (that bit is easy, have been able to grab the right form from all the pages and get the action attribute etc. no bother). Any ideas why this code wouldn't work? (I get no errors and cURL connects and sends something (I see code 200) and upload/download figures).
    <?php
    	
    		
    /*
     * Data which is to submitted to the remote URL
     */
    	$data = array();
    	$data['name'] = 'Mahjong Fever';
    	$data['desc'] = 'Mahjong Fever is about finding matching tiles and collecting points. The amount of points you need for winning the round is displayed next to the game. Good luck! Mahjong is one of the most recognised games in the world. Originally from Asia, like Sudoku, and similar to Money Memo, the aim of the game is to find matching tiles, remove them from the game and build the biggest pile for yourself. In doing so however, you may only take matching tiles which are free on their left or right sides. The game is played until there are no more free tiles to remove. With Mahjong you must, similar to other logic games, always think a couple of moves ahead, to avoid playing the wrong move. Mahjong is so well known that it is often included in computer operating systems, to be played offline. Almost everyone has played this game or seen it played at parties etc. more commonly today probably on their computer. In Asia it is possible to buy handmade Mahjong sets that run to thousands of Euros!';
    	$data['cat'] = 'Board Game';
    	$data['swf'] = 'http://games.mochiads.com/c/g/mahjong_v477723/ad_mahj_load_from_mochi_ad.swf';
    	$data['thumb'] = 'http://www.gimigames.com/img/gallery/mahjongfever(6).png';
    	$data['authorname'] = 'gimigames';
    	$data['authorsite'] = 'www.gimigames.com';
    	
    
    
    /*
     * Prepare data for posting. That is, urlencode data 
     */
    $post_str = '';
    foreach($data as $key=>$val) {
    	$post_str .= $key.'='.urlencode($val).'&';
    }
    $post_str = substr($post_str, 0, -1);
    
    /*
     * Initialize cURL and connect to the remote URL
     * You will need to replace the URL with your own server's URL
     * or wherever you uploaded this script to. 
     */
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'http://www.arcade101.com/');
    
    /*
     * Instruct cURL to do a regular HTTP POST
     */
    curl_setopt($ch, CURLOPT_POST, TRUE);
    
    /*
     * Specify the data which is to be posted
     */
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_str);
    
    /*
     * Tell curl_exec to return the response output as a string
     */
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    
    /**
     * Execute the cURL session
     */
    $response = curl_exec($ch );
    
    /**
     * Close cURL session and file
     */
    curl_close($ch );
    
    echo $response;
    ?>
    	
    	
    	
    


Comments

  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    just a thought, have you considered the possibility that many of the target sites won't use the same naming conventions for their form fields?


  • Registered Users, Registered Users 2 Posts: 19,048 ✭✭✭✭murphaph


    Hi Adam, they all do in fact. thanks for the input though.


  • Registered Users, Registered Users 2 Posts: 19,048 ✭✭✭✭murphaph


    I found the error, stupid one at that: left out a hidden form field completely..added $post_data = 'submit/do'; to my array and away she went. Thanks!


Advertisement