Have form data that is to be sent to our email marketing service database (using cURL). Upon receipt of the data, it bounces back a confirmation page.
The problem is the confirmation page displays above the page that has the form on it. How do I get the confirmation page to render on its own? I believe the problem lies in the cURL script I am using, but can't figure it out.
cURL code:
if ($validForm) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'http://oi.vresp.com?fid=2b68154d4e');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "first_name=$first_name&last_name=$last_name&email_address=$email_address&company_name=$company_name&cust_group=$cust_group");
curl_exec($ch);
curl_close($ch);
Related
I am trying to retrieve information from an external website using cURL, but the website returns a blank page.
I took a close looker at the network functionality Chrome has and I think I found the problem, but I have no idea how to fix it. As seen in the image below, the server posts to a specific URL and then redirects to another one showing the final result.
This is the code I have right now:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://www.politie.nl/aangifte-of-melding-doen/controleer-handelspartij.html?_hn:type=action&_hn:ref=r199_r1_r1_r1");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,"url=&query=test");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
echo curl_exec ($ch);
curl_close ($ch);
The website is in Dutch, but what I am trying to do is check a certain email, phone number or bank account number to see if they have been involved in any scams, so I would like to have the information that a user gets after submitting the form on the website.
The form is on this website: https://www.politie.nl/aangifte-of-melding-doen/controleer-handelspartij.html
I hope someone can help me and thank you for your time.
As was pointed out in one of the comments to your question, a redirect occurs after the form is submitted. But not only that - information transfer between the form submit request and the request after redirect happens through a session, with session id stored in a cookie, so in order to get the results you have to enable cookies, too.
// follow redirects
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
// store and send cookies
$tmpfname = dirname(__FILE__).'/cookie.txt';
curl_setopt($ch, CURLOPT_COOKIEJAR, $tmpfname);
curl_setopt($ch, CURLOPT_COOKIEFILE, $tmpfname);
i need to post raw data (XML) to an external site, the XML data is good to go, and is working with the below example...
I am using PHP / cURL
normally i do this by cURL, but in this instance, i need to redirect the client to the URL with the post data...
It works using the below code, but it won't redirect the user to the $URL, this method just prints the data while still being in the script on the same server.
eg:
Post from site1.com to site2.com, the below method keeps the client on site1, but needs to redirect the user to site2.com with the raw post data...
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_xml);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$val = curl_exec($ch);
curl_close($ch);
i have searched all-over but cannot find a method where it functions as a "regular" form submit where the user is redirected to the URL which the data is posted to... but with RAW post data.
I am trying to use php curl function to log in to a https webpage "https://portal.opalonline.co.uk/Home/PortalCore/SignIn/SignIn.aspx"
but I have run out of ideas how I can post values to this particular page (username, password) and 'press 'sign in'.
$postfields = array('ctl00_MasterContentContentPane_Signin1_userID_txt'=>'email#address.com',
'ctl00_MasterContentContentPane_Signin1_password_txt'=>'somepassword123');
/* LOG IN TO TalkTalk ACCOUNT */
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://portal.opalonline.co.uk/Home/PortalCore/SignIn/SignIn.aspx?");
curl_setopt($ch, CURLOPT_HEADER, false);
// curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIE_FILE);
// curl_setopt($ch, CURLOPT_COOKIE, COOKIE_FILE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_POST, 1);
var_dump($ch);
$string_exec = curl_exec($ch);
var_dump($string_exec);
I can not even display the page with var_dump :( . Ideas / suggestions much appreciated
First, I don't think you can do the 'array' thing like that as that will make PHP/CURL create multipart formpost instead, and this is not such a form. Provide the data in "name=value&name2=value2" style.
Then, make sure you also submit all the hidden fields in the form. There are at least four of them. One of them is set by the HTML to a long value that you need to extract and set, and there is also some javascript magic that sets some of the others. You probably need to use your browser's networking tool to snoop on what exactly your browser sends to be able to mimic that perfectly.
The login page sets cookies and you probably need to pass those cookies on when you submit the login form. So you need to first fetch (GET) the login form page to get the cookies, then file the login POST.
With that fixed, you should be closer. If that isn't all that takes, then continue comparing the browser's request with what your request is sending and make sure they are as similar as possible.
Open the website in google chrome, open the console, to go the network tab.
Login to the website. You should see the request in the network tab. Do a right click on it, select "copy as cURL". It will give you a command line, that will help you understand what you need.
I am currently working on a project which requires me to POST data to an form belonging to a different domain. This does work but I don't want the user to see the data posted to the different domain as it just shows a success / error message (on page B).
What I want to do is have the data POST but the page not change. I have read that AJAX can be used to do this but only if the pages belong to the same domain. windows.location.replaced() looked promising but this only worked if I had access to the external form.
Current implementation:
User enters data on page A > POST data to page B, page B loads
Want I would like to implement:
User enters data on Page A > POST data to page B, page A remains displayed
Make use of cURL to do this.
Page1.php
$url='http://www.domain.com/page2.php';
$params='username=jim&pass=jim321';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
echo $result = curl_exec($ch); // This outputs the response in your same page i.e. Page1.php
curl_close($ch);
try using curl something like this
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://www.otherdoamin.com/page.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,"post1=val1&post2=val2&post3=val3");
// get server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
I have a link I need users to click in order for them to receive a text message. The URL points to an external link so I can't mask it. At present when a user clicks on the link I redirect them to the external site to send the message, but I do not wish to do this as I don't want the user to see the external URL.
I have tried to use file_get_contents() and cURL but I have been unable to get either mechanism to work. When I load the page in the browser I get the text response "OK", when I use PHP to make the request I get the "OK" response from the server but I do not receive the text message to my phone.
Here is the cURL code I have tried:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
return $output;
Using twilio may be able to save you some time here.
Note: Only wrote this here because I cant comment for some reason.