Jump to content

White Page NO ERROR - Calling Function in class


Ansego

Recommended Posts

Hello,

 

I am having some troubles and was hoping someone could guide me through it.

 

Q: When ever I try call my get_status function all I get is a white page of nothing, no errors to work from etc... Can anyone here see what I am doing wrong?

 

 

PATH: index.php

 

NOTICE //<<-- KILLS PAGE

<?php
spl_autoload_register(function ($class) {
    include '/lib/' . $class . '.inc';
});

$servers = new servers;
echo $servers->get_servers(); 
echo "STATUS: ".$servers->get_status("0.0.0.0",80); //<<-- KILLS PAGE
?>

Page works fine until I want to use the status function, I get no errors or anything just a blank page.

 

PATH: Lib/Servers.inc

 

NOTICE //<<-- KILLS PAGE

<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(E_ALL);
error_reporting(-1);

	include_once '../../Global-Includes/ServerStatus/db-connect.php';
	
//namespace xStatus;

class servers {

	private $db_Hostname	= HOSTNAME;
	private $db_Username	= USERNAME;
	private $db_Password	= PASSWORD;
	private $db_Database	= DATABASE;
	
	private $dbSQL			= '';
 
    function __construct() {
		
	} // End Construct
	
		public function get_servers(){
			
			$db = new mysqli($this->db_Hostname,$this->db_Username,$this->db_Password,$this->db_Database); 
		
				$message = '';

				// list current servers from database
				$sql = "SELECT * FROM tbl_servers";
				$res = $db->query($sql);
				
				if ($res->num_rows > 0) {
					
					$message = '<h3>Current Servers</h3>';
					
					while ($row = $res->fetch_assoc()) {
						
						$message .= $row['HostGame'] . '<br>';
						$message .= $row['HostIP'] . '<br>';
						$message .= $row['HostPort'] . '<br>';
						$message .= $this->get_status($row['HostIP'],$row['HostPort']) . '<br>'; //<<-- KILLS PAGE!
						
					}
				}
				
				$message .= "<br>End of the \"Server List\" ";
				
			return $message;
			
			}
		
	
		public function get_status(&$ServerIP,&$ServerPort){
			
			if(@stream_socket_client("tcp://".$this.$ServerIP.":".$this.$ServerPort."", $errno, $errstr, 1) !== false) {
				return "Online";
			} else {
				return "Offline";
			}
			return "Offline";
			}
	
} // End class

?>

Kind regards and thank you.

 

 

 

 

Hi Ch0cu3r.

 

I've moved the error reporting code to index.php with no change to outcome, still white page.

<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(E_ALL);
error_reporting(-1);
?>

I have removed the / from the include but still no change, white page no data.

    include 'lib/' . $class . '.inc';

Ok looking further at your code.

 

Here

public function get_status(&$ServerIP,&$ServerPort){

You have defined the ServerIP and ServerPort arguments can only be  passed by reference (this is what the & means before the variable name). Because of this you cannot pass a hardcoded value (such as string or integer) when calling the method. You can however call it like this

$ip   = "0.0.0.0";
$port = 80;

/* on calling this method $ip and $port will be passed by reference */
echo "STATUS: ".$servers->get_status($ip , $port);

Next remove $this. from in front of the variables on this line (why are you concatenating the object here?). And remove the error suppression operator (  @  ) too.

if(@stream_socket_client("tcp://".$this.$ServerIP.":".$this.$ServerPort."", $errno, $errstr, 1) !== false) {

Hi Ch0cu3r,

 

Well done mate, I removed the ( @ ) and ( & ) and gave me an error:

Catchable fatal error: Object of class servers could not be converted to string in....

Which pointed too:

if(stream_socket_client("tcp://".$this.$ServerIP.":".$this.$ServerPort."", $errno, $errstr, 1) !== false) {

I removed $this and wrapped it with "" and it works great now. End result:

if(stream_socket_client("tcp://$ServerIP:$ServerPort", $errno, $errstr, 1) !== false) {

Giving that reference page you have posted a good read too, cheers.

 

Thanks mate, your awesome!

 

 

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.