简体   繁体   中英

How to call an URL with php without redirect

I'm using an URL to transmit parameters to a remote location. I need to call the URL using PHP - without redirecting to the URL.

I've tried different solutions without luck. I am no way near an expert when dealing with PHP, I am even unsure if I am wording the question correctly.

I've tried:

$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, "https://remotelocation.com/storedata.aspx?name=".$name."&email=".$email_address.);
curl_exec ($curl);
curl_close ($curl);

and:

file_get_contents("https://remotelocation.com/storedata.aspx?name=".$name."&email=".$email_address.")

without any luck.

Calling the URL manually in a browser (using definite values instead of variables) the data is stored. Using mail() instead the data is also transmitted.

I know the solution must be pretty simple. Can anyone help to point me in the right direction?

Not sure why it didn't work with file_get_contents . But for curl you need to add the following few options as well(There are a lot in fact, you can check it from here ).

// to handle https links
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);

// return response
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

And to grab the returned response html

$response_html = curl_exec ($curl);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM