Jump to content

check if valid url


jnerotrix

Recommended Posts

Now I want when form is submitted to check if youtube video is working

 

Would this code work

 

 

$shorturl = $_POST['url'];
$fullurl = "http://www.youtube.com/watch?v=$shorturl"

function check_if_valid($fullurl) {
$res = (($check = @fopen($fullurl, ‘r’)) === false) ? false : @fclose($check);
return ($res == TRUE) ? 1:0 ;
}

 

 

 

But i want it so if the video link is valid it displays

 

This Code

for ($i=0; $i < $numTimes; $i++) {
echo '<object width="$setwidth" height="$setheight""><param name="movie" value="http://www.youtube.com/v/$shorturl&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/$shorturl&hl=en&fs=1$autoplay" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="$allowfullscreen" width="$setwidth" height="$setheight"></embed></object>';
}

 

and if not displays "invalid Video Please Try again" ( And Shows Form again

Link to comment
https://forums.phpfreaks.com/topic/135577-check-if-valid-url/
Share on other sites

is there a way to implement this code into what i need it do

 

<?php
$shorturl = $_POST['url'];
$fullurl = "http://www.youtube.com/watch?v=$shorturl"
$headers = get_headers($fullurl);
if ($headers[0] != 'HTTP/1.1 200 OK') { // Instead display Code
    //If link is bad return to form
}
?>

Link to comment
https://forums.phpfreaks.com/topic/135577-check-if-valid-url/#findComment-706303
Share on other sites

Sinch its defiantly a youtube page, i would just try to oepn it with fopen()...

 

Look up the "allow_url_fopen" flag...

 

it allows fopen() functions to work with URLs (available since PHP 4.0.4)

 

In short it will return '1' if the resulting url connects to a valid page, and '0' if it doesnt.

 

Link to comment
https://forums.phpfreaks.com/topic/135577-check-if-valid-url/#findComment-706309
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.