html - simulate a link call using php code

790

i create a link, in html page, that when it is clicked, it calls a URL to another site, that cause the other site to send a response to a different URL (doesnt matter which one).

i create the html link like this:

print "<a class='login' href='$authUrl'>Connect Me!</a>";

then when i click the link, the other site sends the response ok.

now i need to do the above link call , but in php code, which i believe, means call a GET request using curl?

i tried it so many times but i can't seem to make it work like the link click above. This is my code:

$curl = curl_init();

curl_setopt_array($curl, array(

    CURLOPT_RETURNTRANSFER => 0,
    CURLOPT_URL => $authUrl,

)) $result = curl_exec($curl);

$GLOBALS['log']->fatal("error = " . curl_error($curl));

curl_close($curl);

but it doesn't work and the other site doesn't respond.

i get 1 as a result.

did i call the link ok? is it exactly like clicking on the link in the first example?

511

Answer

Solution:

I use Goutte for that kind of problem. See this repository: https://github.com/fabpot/goutte

It can fill forms or click links and buttons and may help you.

221

Answer

Solution:

You should use:

CURLOPT_RETURNTRANSFER => TRUE,

Otherwise the page content is not returned.

People are also looking for solutions to the problem: jquery - How to add php code in JS file

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.