Deny certain pasted text in $POST['..']

Hey everyone,

I’ve just took 5 minutes to code on a link generator, that takes input submitted with $POST, and generates an <iframe> link. I’ve only used 2 variables for that, but since I actually thought about making it only for YouTube links, how could I only allow to submit youtube.com-related links (only)?

To allow both:


if (!preg_match('~^http:\\/\\/(www\\.)?youtube\\.com~', $_POST['url'])) {
  echo 'Youtube URL's only';
}

:slight_smile:

Ok, thanks. I was just about thinking about the comparison, and if-else statement. I was probably a bit confuzed. The problem now actually is, it doesn’t allow ANY other link of youtube. For example http://www.youtube.com/user/kontor?blend=1&ob=4.

What determines if it’s a youtube link? Starting with http://youtube.com ?


if(strpos($_POST['url'], 'http://youtube.com') !== 0) {
  echo 'You Tube videos only';
}

Finished product, btw: http://doughboys.pytalhost.com/linkgenerator.php

Works. Thank you. :smiley:

Note the difference - his looks for http://youtube.com , you put in http://www.youtube.com

Adjust the pattern.