Jump to content

[SOLVED] Check for meta tag


AXiSS

Recommended Posts

I want to have a feature on my site where the user is provided a meta tag consisting of a random 32 character string, of which they would place on their site's index page. Then I'd have a page on my site that checks if the specified site contains that meta tag. (Similiar to what you need to do if you have ever used Google Webmaster tools)

I am guessing this requires the index page file of the site to be moved into a temporary folder on why server and then it gets scanned for the meta. I think I can do everything up to the scanning part. What would be the best way to do this? Or is there a better way to verify if the user owns that site or not?
Link to comment
https://forums.phpfreaks.com/topic/35992-solved-check-for-meta-tag/
Share on other sites

well say you tell them to put this onto there page
[code]
<META name="sitekey" content="thisisa32keycodeforwebsites12345">
[/code]

then you could use this code to check that they have that key

[code]
  $metakeysite=file_get_contents('http://www.thewebsite.com/');
  $keyposs1 = strpos ($metakeysite, '<META name="sitekey" content="');
  $keyposs2= strpos ($metakeysite, '">', $keyposs1);
  $key= substr($metakeysite, $keyposs1+30, $keyposs2-($keyposs1+30));
[/code]


that should give the variable $key with the key from meta tag and im sure you can do the validation :)

Regards
Liam
  • 4 weeks later...
Not working, using:

[code]$metakeysite = file_get_contents($url);
$keyposs1 = strpos($metakeysite, '<meta name="wakey" content="');
$keyposs2 = strpos($metakeysite, '">', $keyposs1);
$key = substr($metakeysite, $keyposs1+30, $keyposs2-($keyposs1+30));

if($key == $meta_key){
                                        echo 'GOOD!';
                      } else {
                                        echo 'BAD!';
}[/code]

Where $url is the site to check...
So the full code should be something like:

[code]
$contents = file_get_contents($url);

$key = 32charactercodetomatchto12345678;

preg_match("<meta name=\"wakey\" content=\"(.*?)\">",$contents,$matches);
if($matches[1]==$key)
{
echo "Good";
}
else
{
echo "Bad";
}
[/code]

Correct?

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.