Forum Moderators: coopster

Message Too Old, No Replies

Verifying that a provided URL actually exists

(eg verify a video link is really a video link)

         

dgsk387

11:20 pm on Sep 22, 2007 (gmt 0)

10+ Year Member



I'm building an application for my website that will allow a user to submit a YouTube video link via a form and a PHP script will then take that URL and use the YouTube embed code to make the video appear on the page. (Similar to what Facebook allows you to do when you Post Items.)

How can I make sure that the provided URL is really for a video? (eg I don't want them to be able to submit a link to a YouTube user profile page) I want to support a wide range of video sites so I can't just search the provided url for "watch?v=" (for a YouTube video). I need to actually verify the URL is for a video.

I found something here but it only seems to verify the base domain, and not the specific URL.

Any ideas? Thanks!

[edited by: coopster at 2:10 am (utc) on Sep. 23, 2007]
[edit reason] removed url TOS [webmasterworld.com] [/edit]

jatar_k

1:09 pm on Sep 23, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I guess you could use cURL to get the url they post and test what you find

dgsk387

10:29 pm on Sep 23, 2007 (gmt 0)

10+ Year Member



wow, excellent! I've never heard of the cURL library. This looks like the tool I need. Thanks!

EDIT------------

I'm trying this code:

<?php
// create a new curl resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.youtube.com/watch?v=00000000");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// grab URL
$output = curl_exec($ch);

// Get response code
$response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

// Not found?
if ($response_code == '404') {
echo 'Page doesn\'t exist';
} else {
echo $output;
}
?>

The URL is not a valid YouTube video but the script prints "1". What does 1 mean?