Hello All,

I am creating a nagios that will automatically login to my website and display result in Nagios. Currenlty I am able to login using script but my PHP Curl script return full HTML code after login thourgh curl.

here is my script.

<?php

        $id = "username";
        $pw = "password";
        $postfields = "userName=farooq&password=hussaind";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_HEADER, 1); // Get the header
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // Allow redirection
        curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookie");
        curl_setopt($ch, CURLOPT_URL,"http://abc.com/signin.htm");
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2) ");
        curl_setopt($ch, CURLOPT_POSTFIELDS, "$postfields");

        curl_exec($ch);

        $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

#       echo $statusCode;

        if ($statusCode >= 200) {
                echo 'OK - Status Code = '. $statusCode . '. Successfully Login' ;
                exit (0);
        }
        else if ($statusCode >= 400){
                echo 'CRITICAL - Status Code = '.  $statusCode . '. Unable to loging. Please check ';
                exit(2);
        }
        else {
                echo 'UNKOWN - Status Code = '. $statusCode . '. Unable to loging. Please check ';
                exit(1);
        }


        curl_close($ch);
?>

I just want simple message to print without any HTML crap. Like

OK - Status Code = 200 Successfully Login

Please help me in this regard.

Thanks
Farooq Hussain

You can try

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

makes the curl return data instead of output.

Thanks for sharing it!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.