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 6720115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:10:26+00:00 2026-05-26T09:10:26+00:00

I have a script that checks a website ($host) for an string of characters

  • 0

I have a script that checks a website ($host) for an string of characters ($find). If the string exists the nothing happens, if the string is not found then an email is sent to a pre-set email address.

The problem I have is that I need to have an array of URL’s and I believe a second array of text. The text in the array needs to match up to the URL’s in the array.

Perhaps storing the URL’s and text in a text file(s) might be a better solution.

Here is the script as it is right now, working on the single domain.

<?php
    $host = 'www.my-domain.com';
    $find = 'content on my page';

    function check($host, $find) {
        $fp = fsockopen($host, 80, $errno, $errstr, 10);
        if (!$fp) {
            echo "$errstr ($errno)\n";
        } else {
           $header = "GET / HTTP/1.1\r\n";
           $header .= "Host: $host\r\n";
           $header .= "Connection: close\r\n\r\n";
           fputs($fp, $header);
           while (!feof($fp)) {
               $str.= fgets($fp, 1024);
           }
           fclose($fp);
           return (strpos($str, $find) !== false);
        }
    }


    function alert($host) {
        mail('mail@my-domain.com', 'Monitoring', $host.' down');
    }

    if (!check($host, $find)) alert($host);

    ?>

New code with array in place:

$hostMap = array(
    'www.my-domain.com' => 'content on site',
    'www.my-domain2.ca' => 'content on second site',
 );

foreach ($hostMap as $host => $find)
{
        function check($host, $find)
        {
                $fp = fsockopen($host, 80, $errno, $errstr, 10);
                if (!$fp)
                {
                        echo "$errstr ($errno)\n";
                } else {
                        $header = "GET / HTTP/1.1\r\n";
                        $header .= "Host: $host\r\n";
                        $header .= "Connection: close\r\n\r\n";
                        fputs($fp, $header);
                        while (!feof($fp)) {
                                $str.= fgets($fp, 1024);
                        }
                        fclose($fp);
                        return (strpos($str, $find) !== false);
                }
        }

        function alert($host)
        {
                mail('my-email@my-domain.com', 'Website Monitoring', $host.' is down');
        }

        print $host;
        print $find;

//if (!check($host, $find)) alert($host);

        if( !check( $host, $find ) )
        {
                alert($host);
        }
}

?>

Moved the functions outside of the foreach(

ini_set( 'display_errors', true );
        $hostMap = array(
        'www.my-domain.com' => 'content on site',
        'www.my-domain2.ca' => 'content on second site',
     );

          function check($host, $find)
            {
                    $fp = fsockopen($host, 80, $errno, $errstr, 10);
                    if (!$fp)
                    {
                            echo "$errstr ($errno)\n";
                    } else {
                            $header = "GET / HTTP/1.1\r\n";
                            $header .= "Host: $host\r\n";
                            $header .= "Connection: close\r\n\r\n";
                            fputs($fp, $header);
                            while (!feof($fp)) {
                                    $str.= fgets($fp, 1024);
                            }
                            fclose($fp);
                            return (strpos($str, $find) !== false);
                    }
            }

            function alert($host)
            {
                    mail('my-email@my-domain.com', 'Website Monitoring', $host.' is down');
            }

            print $host;
            print $find;

    //if (!check($host, $find)) alert($host);
    foreach ($hostMap as $host => $find)
    {

            if( !check( $host, $find ) )
            {
                    alert($host);
            }
    }

    ?>

Here is the final code with a working Array in case anyone else wants a solution like this.

    function check($host, $find)
    {
        $fp = fsockopen($host, 80, $errno, $errstr, 10);
        if (!$fp)
            {
                            echo "$errstr ($errno)\n";
                        } else {
                            $header = "GET / HTTP/1.1\r\n";
                            $header .= "Host: $host\r\n";
                            $header .= "Connection: close\r\n\r\n";
                            fputs($fp, $header);
                            while (!feof($fp)) {
                                    $str.= fgets($fp, 1024);
                            }
                            fclose($fp);
                            return (strpos($str, $find) !== false);
                        }
    }

function alert($host)
    {
        $headers = 'From: Set your from address here';
        mail('my-email@my-domain.com', 'Website Monitoring', $host.' is down' $headers);
    }

$hostMap = array(
'www.my-domain.com' => 'content on site',
'www.my-domain2.com' => 'content on second site',
);

    //if (!check($host, $find)) alert($host);
    foreach ($hostMap as $host => $find)
    {

            if( !check( $host, $find ) )
            {
                    alert($host);
            }
    }
unset($host);
unset($find);

?>
  • 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-05-26T09:10:26+00:00Added an answer on May 26, 2026 at 9:10 am
    $hostMap = array(
        'www.my-domain.com' => 'content on my page',
        /* etc. */
    );
    
    foreach( $hostMap as $host => $find )
    {
        if( !check( $host, $find ) )
        {
             alert($host);
        }
    }
    

    However, be aware that — depending on the amount of domains you are checking — sequentially mailing large amounts of mails with PHP’s native mail() is not very efficient. You may wanna look in to more specialized mail libraries for that, such as SwiftMailer.

    On the other hand — seeing you are mailing one and the same e-mail address — you could also simply save the failing domains in an array, and mail them all in one e-mail after you’re done checking of course.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script that checks responses from HTTP servers using the PEAR HTTP
I have a script that checks something on my PC every 5 minutes and
I have a script (or more accurately WILL have a script) that checks a
Ok, I have a validation script that checks everything on the form - but
I have a python script that analyzes a set of error messages and checks
I have a little Perl script (On Windows) that checks some files for me
I have a script that checks the value of a Div Id. <div id=hour
I have written a script that checks a set of radiobuttons to be checked.
I have a php script that check if the referrer has been cleared after
I have this script that collects data from users and I want to check

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.