Reply
Youtube Videos
Old 06-24-2008, 01:41 PM Youtube Videos
choskins102's Avatar
Super Talker

Posts: 124
Name: Casey
I want to allow users to add youtube videos using the provided <embed> code that youtube provides. Is there a way to make sure that users don't try to sqlinject or run other code that is not a youtube video?
choskins102 is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 06-24-2008, 02:19 PM Re: Youtube Videos
wayfarer07's Avatar
$frontend->developer

Posts: 1,015
Name: Abel Mohler
Location: Asheville, North Carolina USA
In the stickies there is a section about security http://www.webmaster-talk.com/php-fo...rials-how.html
__________________
Go FREELANCE <=|If a donkey eats a melon, it is still a donkey... |=> Hire Me
wayfarer07 is online now
Reply With Quote
View Public Profile
 
Old 06-24-2008, 02:19 PM Re: Youtube Videos
rogem002's Avatar
Webmaster Talker

Posts: 607
Name: Mike
Location: United Kingdom
Take a look at the code behind:
http://mods.mybboard.net/view/youtube-tag

It's not 100% what you need, but essentially the code there takes the URL of the page were the content is located and generates the embed code.
__________________
Website Services
PHP Code:
if(Added_Talkupation($post) == TRUE){iHug($you);} 
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 06-24-2008, 03:20 PM Re: Youtube Videos
VirtuosiMedia's Avatar
Webmaster Talker

Posts: 734
You might not want to use the code YouTube provides. It doesn't validate, but if you rewrite it, it can still work.
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 06-25-2008, 01:10 AM Re: Youtube Videos
JeremyMiller's Avatar
Full-Time TeraTasker

Posts: 984
Name: Jeremy Miller
Location: Reno, NV
I recently used this to allow people to paste the embed code into a field. It then extracted the YouTube ID code from the pasted code and re-created the HTML. Hope it helps and if anyone sees anything wrong with it, please let me know:
PHP Code:
<?php
list ($g,$code,$g) = explode('youtube.com/'$_POST['youtube']);
list(
$youtube_code,$g) = explode('"',$code);
$youtube_code preg_replace('/[^a-z&\/=0-9]/i','',$youtube_code);
if (
strlen($youtube_code) > 0) {
  
$youtube_file_contents '<object width="425" height="355"><param name="movie" value="http://www.youtube.com/'.$youtube_code.'"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/'.$youtube_code.'" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>';
}
?>
EDIT: I wrote that before I knew that strpos was faster. I don't know that that will be significant in this routine, however.
__________________
Jeremy Miller - TeraTask Technologies, LLC
Content Farmer - Automated Posting for Content & Blog Sites

Last edited by JeremyMiller : 06-25-2008 at 01:11 AM.
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Reply     « Reply to Youtube Videos
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.14785 seconds with 12 queries