Connecting Tech Pros Worldwide Forums | Help | Site Map

curl: posting form variables results in redirection

TJ Talluto
Guest
 
Posts: n/a
#1: Jul 17 '05
Hi,
I'm using the curl functions in php to scrape the wan ip address from my
home router (the router is an SMC product). This is a two step process:
1. post the password value to the login.htm page
2. capture and parse the content from the status_main.htm page

On the SMC's login.htm page there is a form with the following elements:
<form name=tF method=post action=login.htm>
<input type=password name=pws>
<input type=hidden name=page value=login>
<submit value='LOGIN'>

Here are three test cases - only the first two work as expected. I need to
understand why I got that third response... posting the variables causes a
the SMC to give me a redirection to index.htm which does not exist?

COMMAND LINE TEST (returns login.htm and status_main.htm accurately):
curl -d page=login.htm -d pws=mypassword http://10.10.10.1/login.htm
curl http://10.10.10.1/status_main.htm | grep 'wan_ip'

PHP NO-POST TEST(returns login.htm accurately):
$ch = curl_init("http://10.10.10.1/login.htm");
$strIP = curl_exec($ch);
curl_close($ch);

PHP POST TEST (returns an unexpected result):
$ch = curl_init("http://10.10.10.1/login.htm");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "page=login&pws=mypassword");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$strIP = curl_exec($ch);
curl_close($ch);
print "<!-- $strIP -->";

<!-- <html><head><meta http-equiv=refresh content='0;
url=/index.htm'></head></html> -->


--
TJ Talluto
torpedo51 at yahoo dot com

TJ Talluto
Guest
 
Posts: n/a
#2: Jul 17 '05

re: curl: posting form variables results in redirection


> <!-- <html><head><meta http-equiv=refresh content='0;[color=blue]
> url=/index.htm'></head></html> -->[/color]

I have now verified that this is the correct redirection for the first
request (POSTing the variables)... but strangely the second request (GET)
returns the same string. I suspect that subsequent calls are not handled
properly by the curl module... Anyone?

--
TJ Talluto
torpedo51 at yahoo dot com
Manuel Lemos
Guest
 
Posts: n/a
#3: Jul 17 '05

re: curl: posting form variables results in redirection


Hello,

On 11/01/2004 11:10 PM, TJ Talluto wrote:[color=blue][color=green]
>><!-- <html><head><meta http-equiv=refresh content='0;
>>url=/index.htm'></head></html> -->[/color]
>
>
> I have now verified that this is the correct redirection for the first
> request (POSTing the variables)... but strangely the second request (GET)
> returns the same string. I suspect that subsequent calls are not handled
> properly by the curl module... Anyone?[/color]

Probably it is not collecting cookies or handling redirection as needed.

You may want to try this HTTP client class that can do that properly and
let me know if it does not solve the problem.

http://www.phpclasses.org/httpclient


--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
Closed Thread