...

View Full Version : Resolved Post Data, Get Result



zackwiny
08-12-2008, 04:35 PM
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:

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!

zackwiny
08-12-2008, 05:54 PM
Well,
i figured this one out on my own...
all i need to do is change the function to this:


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;
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum