-1

I have a code set on Laravel. This is doing dns verification, I want to verify a specific field in the meta tag I want.

Example code

    public function verifyDomainDns()
{
    $fqdn = sprintf('%s.%s', $this->getVerificationTxtName(), $this->name);
    $results = collect(dns_get_record($fqdn, DNS_TXT));
    $results = $results->where('type', 'TXT')
                       ->where('txt', $this->verification_token);

    $this->domain_verified = $results->isEmpty() ? self::UNVERIFIED : self::VERIFIED;
    $this->save();
}

verification_token Auto-generated numbers registered in database

The meta tag I want to verify.

 <meta name="book" content="verification_token" />
j174288
  • 3
  • 3
  • The backend code you've provided has no correlation as far as I can see to the HTML. Could you explain what meta tags have to do with your backend logic or at least type in pseudo language what you're trying to accomplish? – Stephen Lake Nov 12 '18 at 20:36
  • This is the model file in Laravel. – j174288 Nov 12 '18 at 20:41
  • To be clear, you're trying to fetch data from a meta tag that is generated and rendered by your own application and placed in the tag by your own code? – Stephen Lake Nov 12 '18 at 20:41
  • Sites that sell books. Site owners add this to their site and validate. They will be listed on my site. – j174288 Nov 12 '18 at 20:45
  • Your code is not verifying meta tags, it's verifying TXT DNS records. That's a totally different thing. – Paras Nov 14 '18 at 04:51
  • I know that, How can I do what I want? – j174288 Nov 15 '18 at 12:10

1 Answers1

0

There is no correlation between what your code is already doing and what you want to do.

One way you can achieve this is to get the contents of the URL with something like file_get_contents(), which will result in you getting the HTML content of the URL.

Once you have this, you can use something like DOMXpath to parse it and get the meta tag's contents.

$html = file_get_contents('https://example.com');
$dom = new DomDocument();
$dom->loadHTML($html);
$xpath = new DomXPath($dom);
$contents = $xpath->query('/html/head/meta[@name="book"]/@content');

if ($contents->length === 0) {
    echo 'No tag found';
} else {
    foreach ($contents as $content) {
        echo $content->value;
    }
}
Liam Hammett
  • 1,631
  • 14
  • 18