473,857 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.ht m>
<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_POSTFIE LDS, "page=login&pws =mypassword");
curl_setopt($ch , CURLOPT_RETURNT RANSFER, 1);
$strIP = curl_exec($ch);
curl_close($ch) ;
print "<!-- $strIP -->";

<!-- <html><head><me ta http-equiv=refresh content='0;
url=/index.htm'></head></html> -->
--
TJ Talluto
torpedo51 at yahoo dot com
Jul 17 '05 #1
2 3173
> <!-- <html><head><me ta 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><me ta 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
8773
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 you go to any page in the "member" area without logging in you get directed to a https connection and hit login.php (ie: you end up at https://www.domain.com/login.php). The problem, I believe, lies in the fact that the form on that page...
2
2953
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 (URL redirection). with the following options, CURL does not return the redirection URL. $ch = curl_init(); $ret = curl_setopt ($ch, CURLOPT_URL,
1
13269
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 of the web page that gets returned from the curl form completion. The page I am trying to access is https://retire.hartfordlife.com/index.html and the html block that contains the form is: <form method="post" name="form1"...
5
7432
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, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_URL, $url2); $fp = fopen("example_homepage2.txt", "w"); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,20);
1
1658
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 results from "http://powersports.honda.com/dealer_locator/dealer_locator.asp" However it does not appear to be returning results from the CURL post action. What CURL appears to be doing is finding the page...
1
1848
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 with curl? The same commands? The particular instance I am dealing with is a store locator and it is not as easy as just calling the url with the variables becasue it runs some script behind the scene that does a bunch of calculations for...
5
2444
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 anyone have any ideas how to avoid this?
7
5080
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 and password at https://retire.hartfordlife.com/HartfordOnline/login.html and clicking the "Log In" button please. My intention is to cron the script so that I can automatically retrieve my account balance every morning, but the javascript is...
3
15680
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 setting CURLOPT_FOLLOWLOCATION set to true. I had a problem with my host's updating something in the past that gave me the error "CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set". My host worked on the...
0
9923
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9768
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10808
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10394
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7940
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5774
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5971
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4191
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.