0

I'm going crazy with this. I read some other question about it, but never found an answer.

My problem is: I'm trying to create a PHP Curl request (GET), and the request return false if I set the url from a variable.

Here below my code:

Working code:

$ch = curl_init ();
curl_setopt ($ch, CURLOPT_URL, "www.google.com");
curl_setopt ($ch, CURLOPT_COOKIEFILE, $ckfile); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_PORT, 80);
$output = curl_exec ($ch);
echo json_encode($output);

Not working code:

$url = "www.google.com";
$ch = curl_init ();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $ckfile); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_PORT, 80);
$output = curl_exec ($ch);
echo json_encode($output);

Someone could help me with this? Thank you.

10
  • 2
    Missing = might be the problem, I guess, if it's your real code. It should be $url = "www.google.com"; Commented Feb 5, 2017 at 19:37
  • $url = "google.com", where is aasignment operator (=) Commented Feb 5, 2017 at 19:37
  • is your error_reporting on? Don't you get any error message? Always set error reporting on during development. Commented Feb 5, 2017 at 19:41
  • Sorry, of course there is the "=" it is a wrong cut and paste. Commented Feb 5, 2017 at 19:47
  • No, no getting error :-( Commented Feb 5, 2017 at 19:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.