Click here to Skip to main content
15,867,594 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to write a php function which gets a string, goes to the url I want, puts the string in to a text field in that url, submits it and returns the text shown after submitting. I'm lost guys, help me.

What I have tried:

$html= curl_init('www.thewebsiteiwanttorunmyscripton.com');
Posted
Updated 28-Jun-18 22:54pm
Comments
Richard MacCutchan 28-Jun-18 12:57pm    
Do you mean you want to inject a script into someone else's website? Or are you asking about webscraping? If the latter you can Google for samples.

1 solution

It sounds like you're automatically trying to fill a form on a website, submitting it and then showing the result. I would check the website's source to find the relevant field and see what it does on submitting.

It will look something like this:

HTML
<form method="get" action="/action.php">
  <input type="text" name="field1">
</form> 

The form's method ("get") identifies if you should do a POST or GET request.
The form's action ("/action.php") will give you the URL to request.
The input's name ("field1") will be the name of the parameter.
 
Share this answer
 
Comments
Member 13891176 29-Jun-18 6:11am    
Thank you very much for answering.
I found the part which contains these parameters, but I still don't know how to set/get them. how can I refer to them?
[no name] 29-Jun-18 6:51am    
In my example, the URL would be /action.php?field1=foo if the user entered "foo".
For an example with POST have a look here: https://stackoverflow.com/questions/2138527/php-curl-http-post-sample-code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900