Jump to content

function socket_raw_connect Help?


yuws

Recommended Posts

Well im trying to connect with php sockets to show data.

 

Here's my code..

 

<?php
include("inc/db.php");
include("inc/terms.php");
if ($_COOKIE['agreed'] == $agreement) {


	function checkonline($ext) {
		$address = $ext."no-ip.com";
		$churl = @fsockopen($address, 43594, $errno, $errstr, 1);
		if ($churl) return 0;
		else return 1;
	}

	function socket_raw_connect($ext) {
		$socket = @fsockopen($ext.".no-ip.com", 43597, $errno, $errstr, 1);
		$ret = 0;
		if($socket) { while (!@feof($socket)) { $ret += @fgets($socket, 4096); } }
		else if(!$socket){ $ret = 0; }
		return $ret;
		@fclose($socket);
	}


	function e($w,$m,$s,$h,$p,$l) {
		$r = 0; $lt = "us"; $lte = "Unknown";
		if ($r==0) { echo "<tr>"; $r=1; }
		else { echo "<tr class=r2>"; $r=0; }
		echo "<td class=".($m==0?"f":"m").">";
		if($s==0) echo "<a href=\"play.php?ext=".$h."\">"."World ".$w."</a>";
		else echo "World ".$w;
		echo "</td>";
		if($l == 1){ $lt = "us"; $lte = "US Central 1";}
		if($s == 1) $pop = $p." Players";
		if($s == 0) $pop = "OFFLINE";
		if($s == 2) $pop = "FULL";
		echo "<td>".$pop."</td>";
		echo "<td class=\"".$lt."\">".$lte."</td>";
		echo "<td class=".($m==0?"f>Free":"m>Members")."</td>";
		echo "</tr>";
	}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns:IE>
<head>
<meta http-equiv="Expires" content="0">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta name="MSSmartTagsPreventParsing" content="TRUE">
<title>Funified - the massive online adventure game</title>
<link href="http://funified.com/css/basic.css" rel="stylesheet" type="text/css" media="all">
<link href="http://funified.com/css/server.css" rel="stylesheet" type="text/css" media="all">
</head>
<body>

<div id="body">
<div class="server_list" align="center">
<div style="text-align: center; background: none;">
<div class="titleframe e">
<b>Select a world</b><br>
<a href="http://funified.com/index.php" class=c>Home</a>
</div>
</div>
<br>
<div class="e" style="width: 601px; text-align: center;">
<h1>Quick select (Recommended)</h1>
This will choose the best world for you based on available space and your location.
<div class="text">
<div id="top-text-left">(Free world)</div>
<div id="top-text-right">(Members world)</div>
</div>
<div class="buttons">
<div class="button" id="button-left">
<a href="play.php?ext=w2" class="button"><span class="lev_1"><span>(World 2)</span></span><br><br>Choose best free world for me</a>
</div>
<div class="button" id="button-right">
<a href="play.php?ext=w1" class="button"><span class="lev_1"><span>(World 1)</span></span><br><br>Choose best members only world for me</a>
</div>
</div>
</div>
<br>
<div class="e" style="width: 601px; text-align: center;">
<h1>Advanced select (For experienced players)</h1>
If there is a particular world that you want to use, choose it by clicking on its name.<br>You can reorder the list by clicking on the arrows.
<table class="server" cellpadding="3" cellspacing="0">
<tr class="slist_header">
<td style="border-left: 2px solid #8E7246">
<a href="list.php?order=wMLP"><img src="http://funified.com/images/serverlist/arrow_up.gif" alt="(^)"></a>
<a href="list.php?order=WMLP"><img src="http://funified.com/images/serverlist/arrow_down.gif" alt="(v)"></a>
 World
</td>
<td>
<a href="list.php?order=pMLW"><img src="http://funified.com/images/serverlist/arrow_up.gif" alt="(^)"></a>
<a href="list.php?order=PMLW"><img src="http://funified.com/images/serverlist/arrow_down.gif" alt="(v)"></a>
 Players
</td>
<td>
<a href="list.php?order=lMPW"><img src="http://funified.com/images/serverlist/arrow_up.gif" alt="(^)"></a>
<a href="list.php?order=LMPW"><img src="http://funified.com/images/serverlist/arrow_down.gif" alt="(v)"></a>
 Location (by distance)
</td>
<td style="border-right: 2px solid black">
<a href="list.php?order=mLPW"><img src="http://funified.com/images/serverlist/arrow_up.gif" alt="(^)"></a>
<a href="list.php?order=MLPW"><img src="http://funified.com/images/serverlist/arrow_down.gif" alt="[v]"></a>
 Type
</td>
</tr>
<?php 
		$ListQuery = mysql_query("SELECT * FROM `servers`") or die(mysql_error());
		while($List = mysql_fetch_array($ListQuery)) {
			$h = $List['h'];
			$m = $List['m'];
			$w = $List['w'];
			$s = checkonline($h);
			$p = 0;
			if($s == 1) $p = socket_raw_connect($h);
			$l = $List['l'];
			if($p == 2000) $s = 2;
				e($w,$m,$s,$h,$p,$l);
				//echo $h.$m.$w.$s.$p."!".$l;
		}
?>
</table>
</div>
</div>
</div>
</body>
</html>
<?php
}
?>

 

 

There's something wrong with

function checkonline($ext) {
		$address = $ext."no-ip.com";
		$churl = @fsockopen($address, 43594, $errno, $errstr, 1);
		if ($churl) return 0;
		else return 1;
	}

	function socket_raw_connect($ext) {
		$socket = @fsockopen($ext.".no-ip.com", 43597, $errno, $errstr, 1);
		$ret = 0;
		if($socket) { while (!@feof($socket)) { $ret += @fgets($socket, 4096); } }
		else if(!$socket){ $ret = 0; }
		return $ret;
		@fclose($socket);
	}

in my servers data base 'h' is funified

funified.no-ip.org is my ip.

 

 

i need help connecting!

Link to comment
https://forums.phpfreaks.com/topic/156464-function-socket_raw_connect-help/
Share on other sites

Honestly, you're not the most important member here and none of us are paid to provide help.

 

1. $errno and $errstr are not defined.

2. checkonline() should return 1 if $churl. You got it backwards.

3. @fclose($socket); will never execute because it's after a return statement.

 

Again, patience!

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.