Solved

Form Id with PHP + cURL

Posted on 2004-10-12
12
520 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
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
 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

617 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