Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Aug 2008
    Posts
    17
    Thanks
    4
    Thanked 1 Time in 1 Post

    Post Data, Get Result

    Another question from me...

    is it possible to send so info via the post method with php and get the result url?
    I've been using curl:
    Code:
    function post_data($postd,$url,$follow) {
    	$ch = curl_init();
    	curl_setopt($ch, CURLOPT_URL,$url);
    	curl_setopt($ch, CURLOPT_POST, 1);
    	curl_setopt($ch, CURLOPT_POSTFIELDS,$postd);
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    	curl_setopt($ch, CURLOPT_FOLLOWLOCATION,$follow);
    	$postResult = curl_exec($ch);
    	if (curl_errno($ch)) {
    		return false;
    	}
    	curl_close($ch);
    	return $postResult;
    }
    and:
    $postd = array(
    "Username" => $_POST['user'],
    "Password" => $_POST['pass']
    );

    echo post_data($postd,"http://www.someurl.com/login.php",0);


    but the result is nothing,
    the page is blank.

    What i am trying to get is the url of the resulting page,
    Eg.
    Success: http://www.someurl.com/usercp/
    Fail: http://www.someurl.com/index.php?errorcode=1

    If anyone could help me out with the code i posted or get me some different code then that'd be great!
    Last edited by zackwiny; 08-12-2008 at 05:54 PM.

  • #2
    New Coder
    Join Date
    Aug 2008
    Posts
    17
    Thanks
    4
    Thanked 1 Time in 1 Post
    Well,
    i figured this one out on my own...
    all i need to do is change the function to this:

    Code:
    function post_data($postd,$url,$follow) {
    	$ch = curl_init();
    	curl_setopt($ch, CURLOPT_URL,$url);
    	curl_setopt($ch, CURLOPT_POST, 1);
    	curl_setopt($ch, CURLOPT_POSTFIELDS,$postd);
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    	curl_setopt($ch, CURLOPT_FOLLOWLOCATION,$follow);
    	curl_exec($ch);
    	$postResult = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
    	if (curl_errno($ch)) {
    		return false;
    	}
    	curl_close($ch);
    	return $postResult;
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •