473,324 Members | 2,248 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

curl: posting form variables results in redirection

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
Jul 17 '05 #1
2 3150
> <!-- <html><head><meta http-equiv=refresh content='0;
url=/index.htm'></head></html> -->


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
Jul 17 '05 #2
Hello,

On 11/01/2004 11:10 PM, TJ Talluto wrote:
<!-- <html><head><meta http-equiv=refresh content='0;
url=/index.htm'></head></html> -->

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?


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
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Dave Martin | last post by:
I've successfully used CURL to maneuver around and through sites but a new site I've been trying to work with has got me stumped. To retrieve the data I'm trying to get a login is required. If...
2
by: John Drako | last post by:
I have a database with a lot of links. Every so often I run a script to verify if the URLs are still valid. I weed out the ones with the 404 response. However, many responses are of the 303 kind...
1
by: ynotssor | last post by:
Hello, can someone please tell me the correct way to use "curl" to complete an online form? I am trying to eventually retrieve my account balance via a cron job that will email me the parsed output...
5
by: apinti | last post by:
Here is my code, and the problem: $st="...(string to post is formed from different variables read from file)..."; $lngth=strlen($st); $ch = curl_init(); curl_setopt($ch,...
1
by: devranger | last post by:
Hello, I am in the process of learning PHP CURL and in doing some test examples I am having some issues with CURL that I do not fully understand. I am doing a test to use CURL to post and return...
1
by: devranger | last post by:
I have used curl_setopt($ch, CURLOPT_POST, true); and curl_setopt($ch, CURLOPT_POSTFIELDS, $data); on post forms to retrun results, but what about a GET Form Method? How do you deal with these...
5
by: turnitup | last post by:
I have a security mechanism that checks that session variables are set, and if not, redirects. It seems, however, that CURL just ignores this statement and completely breaches my security. Does...
7
by: h.stroph | last post by:
Greetings, I apologize for my lack of literacy with php, but am wondering if someone will tell me how to use the curl php functions to navigate to the page that results from entering the login...
3
by: Sarah | last post by:
I was wondering if someone might be able to help me with this issue. I have a feeling this has something to do with my host's server settings as I used to be able to get CURL to follow redirects by...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.