开发者

is it easy to give users way to embed youtube videos?

开发者 https://www.devze.com 2023-03-29 08:30 出处:网络
I am just curious is it easy to give access on your webs开发者_如何转开发ite to users so that they can add videos from youtube? If yes can someone share php code how we can do this?It\'s not easy for

I am just curious is it easy to give access on your webs开发者_如何转开发ite to users so that they can add videos from youtube? If yes can someone share php code how we can do this?


It's not easy for security reasons. You can easily get the embed code for a youtube vid and post it on your site, but you don't want to allow users to just post vids without some type of validation, otherwise everyone will write scripts to redirect the page, etc.

I would get the URL and validate it thoroughly. Maybe just parse out the video ID (eg iUZOEBDN3a4) and then reconstruct the embed code yourself using php.

The embed code will be something like this: <iframe width="420" height="345" src="http://www.youtube.com/embed/8I5JVl8u_Yw" frameborder="0" allowfullscreen></iframe>

Then the if you want to share that with other users, say on a video sharing page, just save that code to an html file on your server, and load it to the view page using an include statement.


I would just do

$youtube_id;
$youtube_embed="<iframe width=\"420\" height=\"345\" src=\"http://www.youtube.com/embed/".$youtube_id."\" frameborder=\"0\" allowfullscreen></iframe>";

so i would have them submit the url then pull the youtube id from the youtube url but you have to test to make sure it is a youtube url and that you can get the ID

0

精彩评论

暂无评论...
验证码 换一张
取 消