Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Why Doesn't This Code Work On Computinghost?
krap
post Jul 8 2008, 01:24 AM
Post #1


Super Member
*********

Group: Members
Posts: 204
Joined: 6-October 04
From: London, uk
Member No.: 1,444



Here is the script:
CODE
<html>
<head><title>Rcon Connection Client</title></head>
<body>
<form name="rcon" method="post" action="rcon.php">
IP: <input type="text" name="ip" value="127.0.0.1">
Port: <input type="text" name="port" value="7777">
Password <input type="text" name="pass" size="25"><br>
Cmd: <input type="text" name="cmd" size="100"><br>
<input type="submit" name="submit">
</form>
</body>
</html>
<?
$ip = $_POST['ip']; if (!$ip) die();
$port = $_POST['port']; if (!$port) die();

$pass = $_POST['pass']; if (!$pass) die();
$passlen = strlen($pass);
$cmd = $_POST['cmd']; if (!$cmd) die();
$cmdlen = strlen($cmd);

$packet = 'SAMP';
$packet .= chr(strtok($ip, '.')).chr(strtok('.')).chr(strtok('.')).chr(strtok('.'));
$packet .= chr($port & 0xFF).chr($port >> 8 & 0xFF);
$packet .= "x";
$packet .= chr($passlen & 0xFF).chr($passlen >> 8 & 0xFF).$pass;
$packet .= chr($cmdlen & 0xFF).chr($cmdlen >> 8 & 0xFF).$cmd;

$fp =fsockopen('udp://' . $ip, $port, $errno, $errstr);
fwrite($fp, $packet);
while(!feof($fp)) {
$str=fread($fp,128);
$str=substr($str,13,strlen($str)-13);
if (!$str) break;
echo $str."<br>";
}
fclose($fp);
?>


It seems to work for some other people on different hosts and I've tried on both my websites (one is on alpha, the other on iota) and it doesn't seem to be working. It is a remote control script for the game server I run and it just times out after 60 secs without executing the command on the server sad.gif I am of course replacing the default 127.0.0.1, I know that wouldn't work and I've tested it on another host and it worked fine.
Thanks
Andre

This post has been edited by krap: Jul 8 2008, 01:26 AM
Go to the top of the page
 
+Quote Post
etycto
post Jul 8 2008, 02:54 AM
Post #2


Super Member
*********

Group: [HOSTED]
Posts: 257
Joined: 2-June 07
From: U to the S to the A (but i'm haitian)
Member No.: 44,040



excuse me if i'm wrong: i'm not great with PHP, but i think i see two thing wrong with that. should the script <? ?> be insite the HTML or body tag
like this:
CODE
<html><head><title>Rcon Connection Client</title></head><body><form name="rcon" method="post" action="rcon.php">IP: <input type="text" name="ip" value="127.0.0.1">Port: <input type="text" name="port" value="7777">Password <input type="text" name="pass" size="25"><br>Cmd: <input type="text" name="cmd" size="100"><br><input type="submit" name="submit"></form>
<?  $ip = $_POST['ip'];  if (!$ip) die();  $port = $_POST['port']; if (!$port) die();  $pass = $_POST['pass']; if (!$pass) die();  $passlen = strlen($pass);  $cmd = $_POST['cmd']; if (!$cmd) die();  $cmdlen = strlen($cmd);  $packet = 'SAMP';  $packet .= chr(strtok($ip, '.')).chr(strtok('.')).chr(strtok('.')).chr(strtok('.'));  $packet .= chr($port & 0xFF).chr($port >> 8 & 0xFF);  $packet .= "x";  $packet .= chr($passlen & 0xFF).chr($passlen >> 8 & 0xFF).$pass;  $packet .= chr($cmdlen & 0xFF).chr($cmdlen >> 8 & 0xFF).$cmd;  $fp =fsockopen('udp://' . $ip, $port, $errno, $errstr);  fwrite($fp, $packet);  while(!feof($fp)) {    $str=fread($fp,128);    $str=substr($str,13,strlen($str)-13);    if (!$str) break;    echo $str."<br>";   }  fclose($fp);?>

</body></html>


also should there be a decleration that says it's a PHP script. (maybe it works only for a certain version of PHP did you check that by any chance)
Go to the top of the page
 
+Quote Post
galexcd
post Jul 10 2008, 12:13 AM
Post #3


Define:EVIL PROGRAMMER (ē'vəl prō'grăm'ər)- n. An organism that converts caffeine into evil software.
***********

Group: [HOSTED]
Posts: 1,001
Joined: 25-September 05
From: L.A.
Member No.: 12,251



I'm assuming the page doesn't time out when you comment out the while loop? Since you mentioned this script works on other hosts and not this one I'm assuming it may be an issue with the servers attempting to block data over the ud protocol. I may be mistaken, however that seems to be the only issue I can find. The code should run fine, as long as the server has PHP 4 or higher installed.

@etycto: None of those solutions would cause the page to timeout, however the point about echoing information outside of the body tag might be a good idea if he wants to keep his page at least partly up to par with today's web standards.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Computinghost Cpanel Login Question(7)
  2. Transferring Files From Trap17 To Computinghost(2)
  3. Computinghost Helpdesk Support(1)
  4. Can't "manage" Domain(6)
  5. Computinghost Server Seems Slow(19)
  6. Remote Acces To Mysql In Computinghost.com Server?(2)
  7. Transfering My Website From Trap17.com To Computinghost(5)
  8. How To Cancel Computinghost Reseller's Account(6)
  9. Help On Script For Wap - Line Ip Shower(3)
  10. Delay With Computinghost Customer Support(5)
  11. Can I Upgrade Computinghost Paid Plan? [resolved](3)
  12. Can't Login To Cpanel And The Computinghost Website [resolved](6)
  13. Computinghost Has Lost My Web Site. [resolved](5)
  14. True Or False Mail From Computinghost ? [resolved](8)


 



- Lo-Fi Version Time is now: 21st August 2008 - 01:36 AM