how to get meta tags with php, but with html form

297

I got this PHPsrc:

$tags = get_meta_tags('http://www.autostraddle.com');
echo "CMS is: ";
echo $tags['generator'];

This code is not user friendly; it's not ready for one online tool for my website, because I want create a simple service - CMS detector, and...

$tag = isset($_REQUEST['url']) ? get_meta_tags('url') : '';


<form action="index.php" method="post">
<input type="text" name="url" size="65" value="<?php echo $tag;  ?>"/><br />
<input type="submit" value="Go!">

echo $tag['generator'];

I want create one online tool about detecting what CMS is, but I need this PHP script with HTML form because this will be used from users, and not only from me.

They must put any url, and then the script will perform as described to get the meta tag 'generator'; how do I get the meta tag 'generator'? I want only this meta tag.

Well, and how to do this with 'if else'? if there is meta tag generator do this, but if there is not such tag 'generator', then write any 'echo' message, e.g.

CMS is not known.

Well, this is simple PHP script, but I don't know how to create variables and how to get a URL; mayve with cURL?

406

Answer

Solution:

What you're struggling with is actually getting the user-side input from the POST superglobals. This is something you can try, but there are many ways to implement this. You could also usemethod="SET" and capture the user parameters from URL of theaction="" file.

Notice, in this case, theaction="" parameter is empty. That means the PHP script will execute on the same page where the HTML form is. This might not be what you're trying to do, so if you need to redirect, add the PHP code to a separate file and add it to your website and to theaction="" parameter.

<form action="" method="POST">
    <input type="text" name="url" size="65" placeholder="http://yoururl"/>
    <input type="submit" name="submit" value="Go!">
</form>

<?php
if(isset($_POST['submit']))
{
    $tags = get_meta_tags($_POST['url']);
    if($tags['generator'])
         echo "CMS: <b>" . $tags['generator'] . "</b><br>";
    else
         echo "No CMS info available.<br>";
}
?>

Give this a shot.

People are also looking for solutions to the problem: php - help needed with mysql DISTINCT

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.