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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:36:56+00:00 2026-06-10T08:36:56+00:00

In the code below the get_status() method in my website class returns 1 instead

  • 0

In the code below the get_status() method in my website class returns 1 instead of true or false like I want it to. Can anyone tell me why please? I think it’s probably a mistake in my class, I’m not sure if this line of code is good practice within the get_status() method?

$httpcode = $this->get_httpcode();

When I echo $siteUp it is always 1 whether I put the url as http://www.google.com or http://www.dsfdsfsdsdfsdfsdf.com

I am fairly new to object orientated php and this is my first time teaching myself classes and this is an example I’m building to learn oop. It’s desigened to check a website status and say whether it’s up or down based on the httpcode.

Any tips you have in why this isn’t working would be greatly recieved. Thanks in advance!

class website {
protected $url;

function __construct($url) {
    $this->url = $url;
}

public function get_url() {
    return $this->url;
}

public function get_httpcode() {
    //get the http status code
    $agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
    $ch=curl_init();
    curl_setopt ($ch, CURLOPT_URL,$this->url);
    curl_setopt($ch, CURLOPT_USERAGENT, $agent);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_VERBOSE,false);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSLVERSION, 3);
    $page=curl_exec($ch);
    $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    return $httpcode;
}

public function get_status() {
    $httpcode = $this->get_httpcode();
    if ($httpcode>=200 && $httpcode<400) {
         $siteUp = true;
    } else {
        $siteUp = false;
    }
    return $siteUp;
}
}

// create an instance of the website class and pass the url
$website = new website("http://www.google.com");
$url = $website->get_url();
$httpcode = $website->get_httpcode();
$siteUp = $website->get_status();
echo "site up is set to: " . $siteUp;
  • 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-06-10T08:36:58+00:00Added an answer on June 10, 2026 at 8:36 am

    1 is just how PHP converts “true” to a string

    <?php echo true; ?>
    

    Will display 1.

    In PHP, testing against 1 and testing against true are mostly the same thing.

    $siteUp = $website->get_status() ? "true" : "false";
    

    will make it a string for you to display… but you then can’t test against it for truth, since both “true” and “false” are valid strings and will give you a boolean TRUE.

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

Sidebar

Related Questions

Is there an ide/site that I can use to analyse code below and get
I have a piece of code (below) that can get the text of an
How can I get the code below to output node names that I define?
I can't get the code below to compile (see errors). Advice on correction would
i want disable statusbar in activity, i have use below code, it happen SecurityException,
I have a code that needs to go to the website below and extract
Please review the example code below, I have a class file that is loaded
i am using the below json method and following code to parse json method
Can anyone help? I have a PHP method that sends an http post: <?php
I am using the code below to get processor id: System.Management.ManagementClass theClass = new

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.