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
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
Link to comment
Share on other sites

  • 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...
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.