Connecting Tech Pros Worldwide Forums | Help | Site Map

Problem using curl_setopt for redirection

Marek Möhling
Guest
 
Posts: n/a
#1: Jul 17 '05
I'd like to redirect visitors to a remote location sending post values.


Using:

================================================== ==============
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,
"http://www.ihk-bonn.de/handelsregister/");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"amtsgericht=&dateYear=2004&monthsNr=&registerart= ".
"&cursorStepValue=5&orderby=Handelsregister-Nr.".
"&suchword=kastenholz&s=1&search=www.ihk-bonn.de");
curl_exec($ch);
================================================== ==============

I can retrieve www.ihk-bonn.de's response and print it to the browser, (see
www.peterkastenholz.de/test.php) but what I want is to redirect to
"www.ihk-bonn.de/handelsregister/" with my POST values and the corresponding
result.

I couldn't find code to do this on
www.php.net/manual/en/function.curl-exec.php or curl.haxx.se etc.

Using fsockopen/fputs directly didn't help - same result. Output
buffering prevented the result from being printed to the browser, but I
couldn't fiddle a redirection.

Any clues?
Marek


bn548mm@g214mx.net
(remove numbers to despam)




Janwillem Borleffs
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Problem using curl_setopt for redirection


Marek Möhling wrote:[color=blue]
> I can retrieve www.ihk-bonn.de's response and print it to the
> browser, (see www.peterkastenholz.de/test.php) but what I want is to
> redirect to "www.ihk-bonn.de/handelsregister/" with my POST values
> and the corresponding result.
>[/color]

What you are trying to do can only be achieved by either passing the
arguments to the target host through a Location header (the host should
accept GET requests in this case) or by putting the arguments in a form that
auto-submits (e.g. with JavaScript).


JW



Marek Möhling
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Problem using curl_setopt for redirection


> What you are trying to do can only be achieved by either passing the[color=blue]
> arguments to the target host through a Location header (the host should
> accept GET requests in this case)[/color]

Actually the host in question accepts both POST and GET, but it's form is
set to method="POST", so I guess the GET option is unintentional and can't
be relied on. (they might turn off register_globals eventually...)
[color=blue]
> or by putting the arguments in a form that auto-submits (e.g. with
> JavaScript).[/color]

Yes, but this is unconvenient when JS is turned off and wouldn't allow to be
triggered by cronjobs.
[color=blue]
> What you are trying to do can only be achieved...[/color]
I still hope that the header() function provides a solution.


Marek

bn548mm@g214mx.net
(remove numbers to despam)





Marek Möhling
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Problem using curl_setopt for redirection


Thinking again, this:[color=blue]
> ...and wouldn't allow to be triggered by cronjobs...[/color]
was not so well thought of me

But:[color=blue]
> so I guess the GET option is unintentional and can't
> be relied on. (they might turn off register_globals eventually...)[/color]
is still a valid concern


Marek

bn548mm@g214mx.net
(remove numbers to despam)


Marek Möhling
Guest
 
Posts: n/a
#5: Jul 17 '05

re: Problem using curl_setopt for redirection


Thinking again again, it really can't be done as I'd like it to...:-(
M


Closed Thread