php - Is there any frontend technique like file_get_contents() that works cross-origin?
Get the solution ↓↓↓I'm streaming Google Drive videos, and I have two ways of doing it:
<video>
<source src="https://www.googleapis.com/drive/v3/files/videoXXX?key=APIXXX&alt=media">
</video>
or
<video>
<source src="https://drive.google.com/uc?export=download&id=videoXXX">
</video>
They both work reasonably well for small files, but they grab the fullsized video on divs that are never more than 200 pixels wide. There's a big jump in size on my files from 12 to 88mb. Everything smaller than the 12mb works and everything larger than the 88 does not, so there's a cutoff somewhere between them.
I've found that by physically visiting the URL with format https://drive.google.com/file/d/videoXXX/view, I can reduce the quality and then right click and get the URL of the low res file.
I've also managed to get that URL withfile_get_contents("https://drive.google.com/file/d/videoXXX/view")
and parsing the result. You can do exactly the same thing with the URL https://docs.google.com/get_video_info?docid=videoXXX.
The problem is that this URL is dependent on the user's IP address, and embedding it into the video tag doesn't work (copying and pasting it into the browser also doesn't work), because it's locked to the server's IP.
I've tried retrieving it with Ajax, loading the video in an iframe and grabbing the source, and most recently by trying to download the server's IP-locked URL onto the server and play it from there.
Barring te most recent one, I know it's because I can't do this cross-origin, but why is PHP able to do it? How can I load this page and/or grab that URL client-side, from the user's IP adddress?
Answer
Solution:
I know it's because I can't do this cross-origin, but why is PHP able to do it?
Because cross origin is enforced in the browser, not the server. PHP ignores the cross origin headers. Browsers will enforce them. There is no way around them without modifying and recompileing the browser source. If there was a way around CORS it would be useless and wouldn’t exist.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: illegal string offset
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.
Similar questions
Find the answer in similar questions on our website.
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.