Is there something wrong with my coding?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

May I ask how much experience you have as a developer in general and php in particular?
FiOh
Forum Commoner
Posts: 39
Joined: Tue Dec 12, 2006 12:20 am

Post by FiOh »

I'm sorry to say that i have no experience at all and i am not a developer. I am just a student but my project supervisor has assigned this project to me.

>.<
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

wow, that's tough.
Ok, let's what you've done.

Code: Select all

// 1
function my_abc() {
	// 3
	my_abc();
}

// 2
my_abc();
there's a defintion for the function my_abc (1) and it's called at (2). But within the function it is calling itself(3) again - without any condition not to do so. Therefore it will call itself again and again until the callstack shows it the finger.

Code: Select all

error_reporting(E_ALL); ini_set('display_errors', true);
function my_abc($n) {
	if ( 0==$n%1000 ) {
		echo $n, " ";
	}
	my_abc($n+1);
}
my_abc(0);
gives me
0 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 11000 12000 13000 14000 15000 16000 17000 18000 19000 20000 21000 22000 23000 24000 25000 26000 27000 28000 29000 30000 31000 32000 33000 34000 35000 36000 37000 38000 39000 40000 41000 42000 43000 44000 45000 46000 47000 48000 49000
so, after approx. 49000 times my_abc calling itself the callstack had enough and terminated this instance of php.

Same here
FiOh wrote:function my_fgets($fp, $maxlen) {
...
$s = my_fgets($fp, $maxlen);
...
}

function my_fputs($fp, $s, $len=null) {
...
return ( is_null($len) ) ? my_fputs($fp, $s) : my_fputs($fp, $s, $len);
}
Of course it's not always bad when a function calls itself, see http://en.wikipedia.org/wiki/Recursion_ ... science%29
But then there's a stop condition somewhere.

Change it back to

Code: Select all

function my_fgets($fp, $maxlen) {
	$read = array($fp); $write=$except=null;
	while( false===stream_select($read, $write, $except, 1) ) {
		echo '<div>', date('H:m:i'), " - idle</div>\n"; flush();
	}
	
	$s = fgets($fp, $maxlen);
	echo '<div>', date('H:m:i'), ' Debug my_fgets: ', htmlentities($s), "</div>"; flush();
	return $s;
}
	
function my_fputs($fp, $s, $len=null) {
	echo '<div>', date('H:m:i'), ' Debug my_fputs: ', htmlentities($s), "</div>"; flush();
	return ( is_null($len) ) ? fputs($fp, $s) : fputs($fp, $s, $len);
}
but keep the my_fgets and my_fputs in the remaining script.
FiOh
Forum Commoner
Posts: 39
Joined: Tue Dec 12, 2006 12:20 am

Post by FiOh »

Here's the output the browser returns:
13:01:22 Debug my_fgets: ÿûÿûÿýÿý
13:01:22 Debug my_fputs: cl li 35
13:01:22 Debug my_fputs:
13:01:22 Debug my_fputs:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets: User Access Verification
13:01:22 Debug my_fgets:
13:01:22 Debug my_fputs: cl li 35
13:01:22 Debug my_fputs:
13:01:22 Debug my_fputs:
13:01:22 Debug my_fgets: Password:
13:01:22 Debug my_fgets: Password:
13:01:22 Debug my_fgets: Password:
13:01:22 Debug my_fputs: cl li 35
13:01:22 Debug my_fputs:
13:01:22 Debug my_fputs:
13:01:22 Debug my_fgets: % Bad passwords
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fputs: cl li 35
13:01:22 Debug my_fputs:
13:01:22 Debug my_fputs:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fputs: cl li 34
13:01:22 Debug my_fputs:
13:01:22 Debug my_fputs:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fputs: cl li 34

Notice: fputs() [function.fputs]: send of 8 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19

13:01:22 Debug my_fputs:

Notice: fputs() [function.fputs]: send of 1 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19

13:01:22 Debug my_fputs:

Notice: fputs() [function.fputs]: send of 1 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19

13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fputs: cl li 34

Notice: fputs() [function.fputs]: send of 8 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19

13:01:22 Debug my_fputs:

Notice: fputs() [function.fputs]: send of 1 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19

13:01:22 Debug my_fputs:

Notice: fputs() [function.fputs]: send of 1 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19

13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fputs: cl li 34

Notice: fputs() [function.fputs]: send of 8 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19

13:01:22 Debug my_fputs:

Notice: fputs() [function.fputs]: send of 1 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19

13:01:22 Debug my_fputs:

Notice: fputs() [function.fputs]: send of 1 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19

13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fputs: 2r2

Notice: fputs() [function.fputs]: send of 3 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19

13:01:22 Debug my_fputs:

Notice: fputs() [function.fputs]: send of 2 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19

13:01:22 Debug my_fputs:

Notice: fputs() [function.fputs]: send of 2 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19

13:01:22 Debug my_fputs:

Notice: fputs() [function.fputs]: send of 2 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19

13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fputs: ÿý

Notice: fputs() [function.fputs]: send of 3 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19

13:01:22 Debug my_fputs: ÿý

Notice: fputs() [function.fputs]: send of 3 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19

13:01:22 Debug my_fputs: ÿû

Notice: fputs() [function.fputs]: send of 3 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19

13:01:22 Debug my_fputs: ÿû

Notice: fputs() [function.fputs]: send of 3 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19

13:01:22 Debug my_fputs: ÿúP<

Notice: fputs() [function.fputs]: send of 7 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19

13:01:22 Debug my_fputs: ÿð

Notice: fputs() [function.fputs]: send of 2 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19

13:01:22 Debug my_fputs: ÿúANSI

Notice: fputs() [function.fputs]: send of 8 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19

13:01:22 Debug my_fputs: ÿð

Notice: fputs() [function.fputs]: send of 2 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19

13:01:22 Debug my_fputs:

Notice: fputs() [function.fputs]: send of 1 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19

13:01:22 Debug my_fgets:
13:01:22 Debug my_fputs:

Notice: fputs() [function.fputs]: send of 1 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19

13:01:22 Debug my_fgets:
13:01:22 Debug my_fputs: class

Notice: fputs() [function.fputs]: send of 6 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19

13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fputs: en

Notice: fputs() [function.fputs]: send of 3 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19

13:01:22 Debug my_fputs: class

Notice: fputs() [function.fputs]: send of 6 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19

13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fputs: terminal length 0

Notice: fputs() [function.fputs]: send of 18 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19

13:01:22 Debug my_fputs: show run

Notice: fputs() [function.fputs]: send of 8 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19

13:01:22 Debug my_fputs:

Notice: fputs() [function.fputs]: send of 1 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 19

13:01:22 Debug my_fgets:

Notice: Undefined variable: moredetails in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver_D\cisco2612\Login_Process.php on line 146

13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets:
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

13:01:22 Debug my_fgets: ÿûÿûÿýÿý
13:01:22 Debug my_fputs: cl li 35
13:01:22 Debug my_fputs:
13:01:22 Debug my_fputs:
13:01:22 Debug my_fgets:
13:01:22 Debug my_fgets: User Access Verification
13:01:22 Debug my_fgets:
13:01:22 Debug my_fputs: cl li 35
13:01:22 Debug my_fputs:
13:01:22 Debug my_fputs:
13:01:22 Debug my_fgets: Password:
13:01:22 Debug my_fgets: Password:
13:01:22 Debug my_fgets: Password:
13:01:22 Debug my_fputs: cl li 35
13:01:22 Debug my_fputs:
13:01:22 Debug my_fputs:
13:01:22 Debug my_fgets: % Bad passwords
looks like it's wrong from (almost) the beginning. The script does not send what is expected at this stage. The server gave it a few tries and then hanged up
13:01:22 Debug my_fputs: cl li 34

Notice: fputs() [function.fputs]: send of 8 bytes failed with errno=10053 An established connection was aborted
FiOh
Forum Commoner
Posts: 39
Joined: Tue Dec 12, 2006 12:20 am

Post by FiOh »

What should i do now?
8O
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Somehow you have to figure out how this protocol actually works. Who wrote the script? Can't you ask that person?
FiOh
Forum Commoner
Posts: 39
Joined: Tue Dec 12, 2006 12:20 am

Post by FiOh »

I would be happier if i am able to ask the guy who wrote this script. He is the 1st student who got this project, a top student but he has already graduated from my school and i do not know him.
T-T
FiOh
Forum Commoner
Posts: 39
Joined: Tue Dec 12, 2006 12:20 am

Post by FiOh »

May i know if i were to write my own coding for the telnet connection i can use the following coding?

Code: Select all

<?php
require_once "PHPTelnet.php";

$telnet = new PHPTelnet();

// if the first argument to Connect is blank,
// PHPTelnet will connect to the local host via 127.0.0.1
$result = $telnet->Connect('www.somewhere.com','login name','password');

if ($result == 0) { 
$telnet->DoCommand('enter command here', $result);
// NOTE: $result may contain newlines
echo $result;
$telnet->DoCommand('another command', $result);
echo $result;
// say Disconnect(0); to break the connection without explicitly logging out
$telnet->Disconnect(); 
}
?>
Source: http://www.geckotribe.com/php-telnet/

So do i replace the 'www.somehere.com' with the terminal server's ip address? But i have telnet password and enable password to login to the terminal server yet in the

Code: Select all

$result = $telnet->Connect('www.somewhere.com','login name','password');
there is only one password field. For the 'enter command here' what command should i put?

How should i do it?
:?:
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

I really don't know wether you can use this telnet class or not since I don't know the difference between "Direct Telnet" and "via the Terminal Server"
FiOh wrote:I have no problem connecting to the networking devices via the Direct Telnet but i am not able to connect to the networking devices via the Terminal Server.
FiOh
Forum Commoner
Posts: 39
Joined: Tue Dec 12, 2006 12:20 am

Post by FiOh »

volka wrote:I really don't know wether you can use this telnet class or not since I don't know the difference between "Direct Telnet" and "via the Terminal Server"
FiOh wrote:I have no problem connecting to the networking devices via the Direct Telnet but i am not able to connect to the networking devices via the Terminal Server.
It is to use PHP scripts to make telnet connections. PHP Telnet 1.1.
Does anyone knows how should i do that?
Post Reply