Jump to content

Simple OO Example: How to check if a Yahoo user is Online


keeB

Recommended Posts

<?php

/* object checks to see if yahoo user is logged in or out */

/**
   * @author: nick stinemates
   */

class yahoo {

private $name; 
private $YAHOO_URL = "http://216.155.194.208/online?u=";

    function yahoo($name) {    
    	$this->setName($name);	
    }
    
    public function setName($name) {
    	$this->name = $name;
    }
    
    public function check() {
    	if(!isset($this->name)) {
    		throw new Exception("choose a name to check, dumbass");
    	}
    	
    	$x = file_get_contents($this->YAHOO_URL . $this->name);
	if(strlen($x) == 140) return "online";
	return "not online";
    }   
    
}


$y = new yahoo("nickstinemates2");
print $y->check();


?>

 

I was bored at work so I wrote this. Maybe not the best example of OO principals, but these are they types of things I wrote to learn how to program.

 

Hope it's helpful to someone ;)

 

I am used to developing setter/getter methods apart of my C++/Java endeavors.

 

check() returned the image of the URL originally, but I quickly added the string when posting this, didn't even think of using a boolean (all i did was change the return values)

 

Appreciate the criticism, though!

Archived

This topic is now archived and is closed to further replies.

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