Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8264705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:33:05+00:00 2026-06-08T04:33:05+00:00

I have put together php code that will notify if a YT video is

  • 0

I have put together php code that will notify if a YT video is valid or invalid. Since I only want URLs from the YT domain I have set an array to catch any other URL case and return an error. The problem is that when I type a URL in a format like: www.youtube.com/v/NLqAF9hrVbY i get the last echo error but when I add the http in front of that URL it works find. I am checking the $url with PHP_URL_HOST .

Why is it not accepting URLs of the allowed domain without the http?

PHP

if ($_POST) {
    $url = $_POST['name'];

    if (!empty($url['name'])) {
        $allowed_domains = array(
            'www.youtube.com',
            'gdata.youtube.com',
            'youtu.be',
            'youtube.com',
            'm.youtube.com'
        );

        if (in_array(parse_url($url, PHP_URL_HOST), $allowed_domains)) {

            $formatted_url = getYoutubeVideoID($url);
            $parsed_url = parse_url($formatted_url);
            parse_str($parsed_url['query'], $parsed_query_string);
            $videoID = $parsed_query_string['v'];

            $headers = get_headers('http://gdata.youtube.com/feeds/api/videos/' . $videoID);

            if ($videoID != null) {

                if (strpos($headers[0], '200')) {
                    echo('<div id="special"><span id="resultval">That is a valid youtube video</span></div>');

                }
                else {

                    echo('<div id="special"><span id="resultval">The YouTube video does not exist.</span></div>');
                    return false;
                }

            }
            {

                echo('<div id="special"><span id="resultval">The YouTube video does not exist.</span></div>');
                return false;
            }
        }
        else {

            echo ('<div id="special"><span id="resultval">Please include a video URL from Youtube.</span></div>');

        }
        ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T04:33:07+00:00Added an answer on June 8, 2026 at 4:33 am

    parse_url() needs to be given valid URLs with protocol identifier (scheme – e.g. http) present. This is why the comparison fails.

    You can fix this as follows.

    if(substr($url, 0, 4) != 'http')
    $url = "http://".$url;
    

    Use the above before performing

    if(in_array(parse_url($url, PHP_URL_HOST), $allowed_domains)){ ... }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Last night I tried to put together something that I have had working since
I have a little php/mysql app I put together that takes an input form
I have a php script that I've put together from examples on the internet.
I have put together an API that responds to a POST request by putting
I have MANY small Test Projects where I put together just enough code to
We've put together an app that is mostly working in phonegap. We have an
I have put together a small contacts management app in php for my personal
I have a table that's generated by a normal PHP loop. What I want
I am new to the world of PHP and have put together a form
Basically, i have a site put together with PHP, HTML and CSS. I had

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.