0

i am using curl to open a page and want to play video using javascript that was shown on the page . i have used following code

$url = "https://www.example.com/";
$link = "http://www.example.com/oembed?url=" . $url. "&format=json";
$curl = curl_init($link);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($curl);
curl_close($curl);
$result = json_decode($return, true);
echo '<pre>'; print_r($result);
echo $result['html'];

play();

function play(){

   document.getElementById("play-button").click();
}

my curl is working but it didn't play the video.where am iI wrong? do i have pass the x-path of the button to play video?

blitz
  • 21
  • 2
  • 4

1 Answers1

0

PHP scripts are executed on the server, while JavaScript is executed on the browser (Node.js is an exception). Thus your PHP code is already executed when the JS wanted to call the click action and there's no way that the PHP code will execute on the browser, thus the curl is not getting called.

What you need to do is call the URL using JavaScript asynchronously. You can either use Ajax or Fetch for this.

0xC0DED00D
  • 19,522
  • 20
  • 117
  • 184