Jump to content

White Page NO ERROR - Calling Function in class


Ansego
Go to solution Solved by Ch0cu3r,

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.

 

 

 

 

Link to comment
Share on other sites

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';
Link to comment
Share on other sites

  • Solution

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) {
Edited by Ch0cu3r
Link to comment
Share on other sites

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!

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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