cURL post form problem

Discussion in 'PHP' started by bumbar, Feb 28, 2008.

  1. #1
    Hallo!

    I have two files: curl.php and form.php.

    curl.php
    
    $ch = curl_init("http://localhost/form.php");
      
      	
       $params = "txt=4234243&submit=submit"; //you must know what you want to post
        
      
      	    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
                curl_setopt($ch, CURLOPT_POST, 1);
                curl_setopt($ch, CURLOPT_POSTFIELDS, "$params");
      
      
       $result = curl_exec($ch);
       curl_close($ch);
       print $result;
    
    PHP:
    form.php
    
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <input name="txt" type="text" />
    <input name="submit" type="submit" value="submit" />
    </form>
    
    
    <?php
    if (isset ($_POST['submit'])) {
    
    	$text = $_POST['txt'];
    
    		if ((int)$text) {
    		
    		header ("Location: http://localhost/form.php?new=$text");
    		
    		} else {
    		
    		header ("Location: http://localhost/form.php?error=1");
    		
    		}
    
    }
    
    
    if (isset ($_GET['new'])) {
    
    	echo "You typed right message" . $_GET['new'];
    
    } 
    
    if (isset ($_GET['error']) == '1') {
    
    	echo "Wrong!....";
    
    } 
    
    ?>
    
    PHP:

    When launching curl.php emerges order form.
    When completing form and pressing the button I forward in form.php and receive the data there (in form.php)....

    How the result is got In curl.php?

    Is there any cURL guru?
    Thanx!;)
     
    bumbar, Feb 28, 2008 IP