cURL Help !

Discussion in 'PHP' started by priyakochin, Jun 16, 2007.

  1. #1
    I got a sample code from one of the sites.Its like this :



    Why this code is not working ?

    I doubt abt it !

    Can anyone plz help with some other examples ?
     
    priyakochin, Jun 16, 2007 IP
  2. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #2
    It's impossible to tell without seeing the code inside gurl.php

    Perhaps you'll have more luck with this ....

    
    <?
    class curl
    {
    	var $curl ;
    	
    	function curl( )
    	{
    		if( !( $this->curl = curl_init( ) ) )
    		{
    			die( "Cannot initialize curl, please make sure it is loaded" );	
    		}	
    		curl_setopt( $this->curl, CURLOPT_RETURNTRANSFER, true );
    		curl_setopt( $this->curl, CURLOPT_FOLLOWLOCATION, true );
    	}
    	function request( $method, $url, $post = null )
    	{
    		if( strtolower( $method ) == "post" )
    		{
    			if( !curl_setopt( $this->curl, CURLOPT_POST, true ) )
    				die( sprintf( "Failed to setup curl post : %s", curl_error( $this->curl ) ) );	
    			if( !curl_setopt( $this->curl, CURLOPT_POSTFIELDS, $this->_serialize( $post ) ) )
    				die( sprintf( "Failed to setup curl post data : %s", curl_error( $this->curl ) ) );		
    		}	
    		if( !curl_setopt( $this->curl, CURLOPT_URL, $url ) )
    		{
    			die( sprintf( "Failed to setup curl url : %s", curl_error( $this->curl ) ) );
    		}
    		else
    		{
    			return curl_exec( $this->curl );
    		}
    	}
    	function _serialize( $post )
    	{
    		foreach( $post as $key => $value )
    		{
    			$result[ ] = sprintf( '%s=%s', $key, urlencode( $value ) );
    		}	
    		return implode('&', $result );
    	}
    }
    $curl = new curl ;
    
    /**
    POST EXAMPLE, you could replace the array( ) with $_POST if you're sendin a whole form
    echo $curl->request( 'POST', 'http://krakjoe.com/post-ajax.php',  array( 
    		'first' => 'Joe',
    		'last' => 'Watkins',
    		'age' => 23
    ));
    **/
    
    /**
    GET EXAMPLE
    echo $curl->request('GET', 'http://krakjoe.com' );
    **/
    ?>
    
    PHP:
     
    krakjoe, Jun 17, 2007 IP
  3. priyakochin

    priyakochin Banned

    Messages:
    4,740
    Likes Received:
    138
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thankz !
    It works !

    But when I try to do it for some directory submission its not working !

    Why its like that ?
     
    priyakochin, Jun 17, 2007 IP
  4. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #4
    directories often have other measures to make sure that the posted data has come from a form on the domain, I would firstly get ahold of the source to the directory you're using a do a search in it for $_SERVER to see if any other detection is going on, other than that the only thing I can think of is there are hidden form fields on the page filled by javascript onsubmit ( or not, if they were missing the data will still be incorrect ) and obviously you cannot use curl to submit forms that use captcha verification.
     
    krakjoe, Jun 17, 2007 IP
  5. priyakochin

    priyakochin Banned

    Messages:
    4,740
    Likes Received:
    138
    Best Answers:
    0
    Trophy Points:
    0
    #5
    This is the code !
    Plz check it !

     
    priyakochin, Jun 17, 2007 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    The value for CATEGORY_ID needs to be a number, as found in the value attribute of the option.

    Also, for some reason you're assigning $webresult (Wherever it comes from...), and later you're echoing $webresult, which apparently isn't the same.

    I can't test it since I don't have gurl.php. So I suggest you show some effort and try to do it yourself first, instead of asking us to "plz check it"...

    EDIT:

    You're also trying to put HTML code directly in a text area. You have to convert the HTML from the page to HTML entities.

    
    printf("Result:<br><textarea rows='20' cols='50'>%s</textarea><br>", htmlspecialchars($webresult));
    
    PHP:
     
    nico_swd, Jun 18, 2007 IP