Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

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

Posts: 136
Name: Casey
Trades: 3
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
 
 
Register now for full access!
Old 06-24-2008, 03:19 PM Re: Youtube Videos
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
In the stickies there is a section about security http://www.webmaster-talk.com/php-fo...rials-how.html
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 06-24-2008, 03:19 PM Re: Youtube Videos
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
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.
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 06-24-2008, 04:20 PM Re: Youtube Videos
VirtuosiMedia's Avatar
Web Design Made Simple

Posts: 1,228
Trades: 0
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, 02:10 AM Re: Youtube Videos
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
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

Please login or register to view this content. Registration is FREE

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

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB 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.14762 seconds with 12 queries