Solved

Form Id with PHP + cURL

Posted on 2004-10-12
12
473 Views
Last Modified: 2012-06-27
Hi,

I hope someone can help me with a small info.


I 'm trying to post following form data using cURL to IIS server (not under my control), but remote site is obviusely checking »form id«.
Question is how to send »form id« via cURL?

HTML
<form  id=admin action="www.somesite.com/test.asp" method="POST">
<input type="hidden" name="var1" value="1">
<input type="hidden" name="var2" value="2">
<input type="hidden" name="var3" value="3">
    <input type="submit" name="button" value="push">
</form>

PHP + cURL
<?
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL," www.somesite.com/test.asp");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
            "var1=1&var2=2&var3=3id=admin");

curl_exec ($ch);
curl_close ($ch);
?>


Any Ideas?

Thx, Robert
0
Comment
Question by:Whisky
  • 4
  • 3
  • 3
12 Comments
 
LVL 48

Expert Comment

by:hernst42
ID: 12286075
What is missing in your postfield is the button=push
try this:

curl_setopt($ch, CURLOPT_POSTFIELDS,
            "var1=1&var2=2&var3=3&button=push");
0
 

Author Comment

by:Whisky
ID: 12286230
Hi hernst42,

I tried that option too, but no luck.
My wild guess would be that remote site is using "Request.Form("id")" method for checking
0
 
LVL 48

Expert Comment

by:hernst42
ID: 12286364
I have used you example code and looked into the transmitted HTTP-protocol there where only those 4 variables sent to the webserver:

var1=1&var2=2&var3=3&button=push
0
 
LVL 10

Expert Comment

by:frugle
ID: 12286565
Request.Form("id")

would return "admin" if you also had <input type="hidden" name="id" value="admin">

your wild guess is quite inaccurate. <form id= ID is used by Javascript in validation, e.g. document.id.submit(); to call the submit routine on that particular form.

The server is more likely to be picking up the referring page and throwing your input out.

Mike
0
 

Author Comment

by:Whisky
ID: 12286719
My HTML example code IS working,

and PHP+cURL is NOT, I'm not very familiar with .asp so my guess is / can be inaccurate.

How to solve the problem is basic question ... any more ideas?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 10

Expert Comment

by:frugle
ID: 12286779
var1=1&var2=2&var3=3id=admin

should be

var1=1&var2=2&var3=3&id=admin
                                   ^ note
Mike
0
 

Author Comment

by:Whisky
ID: 12288213
Tried ... var1=1&var2=2&var3=3&id=admin ... NOT working

I'm posting to .asp page (which structure or code I have not seen), so I can not say how it functions or what it checks, but never the less HTML example (resides on my server so the referer can not be a problem) which I posted a few posts up ... is working, So only difference between HTML example and cURL is "form id", also if I throw "form id" out, HTML example does not work anymore.
0
 
LVL 48

Accepted Solution

by:
hernst42 earned 250 total points
ID: 12288560
You might try a network sniffer which log the packets send by your browser to that asp-page and see which information is posted to the asp page, then check what you curl-request is send and what might be missing. (For Windows I don't know such a tool. On Unix use ethereal e.g.)
0
 
LVL 10

Assisted Solution

by:frugle
frugle earned 250 total points
ID: 12288722
http://www.htmlhelp.com/reference/html40/attrs.html#id

The ID attribute uniquely identifies an element within a document. To my knowledge it is not passed by the browser.


The problem is more likely to be cURL, and the fact that it sends data as application/x-www-form-urlencoded

Is it possible to give more information on the server that you are communicating with and the variables you are sending?

Mike
0
 
LVL 10

Expert Comment

by:frugle
ID: 12482943
no objections here, though would be nice to know if the questioner actually solved the problem with our advice.

Mike
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now