Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-12-2008, 04:35 PM   PM User | #1
zackwiny
New Coder

 
Join Date: Aug 2008
Posts: 17
Thanks: 4
Thanked 1 Time in 1 Post
zackwiny is an unknown quantity at this point
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..
zackwiny is offline   Reply With Quote
Old 08-12-2008, 05:54 PM   PM User | #2
zackwiny
New Coder

 
Join Date: Aug 2008
Posts: 17
Thanks: 4
Thanked 1 Time in 1 Post
zackwiny is an unknown quantity at this point
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;
}
zackwiny is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:27 AM.


Advertisement
Log in to turn off these ads.