Hi! I am new to PHP program.. I m doin a project which requires me to configure my routers and switches using PHP Programming.
I get this error when i try to run this program. Hope someone might be able to help me out. Thnx alot! This is the error i get:
Parse error: syntax error, unexpected $end in C:\Program Files\Apache Group\Apache2\htdocs\Multivendor\cisco1200\General.php on line 226

<? session_start(); ?>

<?
//session created for security purpose and to protect outsider directly entry the webpage
if ($_SESSION['login'] == "")
{
echo "<script type=\"text/javascript\"> alert(\"You must LOG IN to access this page.\"); </script>";
echo "<script type=\"text/javascript\"> self.location=\"Login.php\"; </script>";
exit();
}

?>

<?

$filename = "Login_Info.txt";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
$login_info = explode(",", $contents);

$host = $login_info[0];
$port = 23;
//$newHostname = $_POST['devicename'];

//Start of configuration when hostnames input field is not empty.
if($_POST['devicename'] != "")
{
	$fp = fsockopen($host,$port,$errno,$errstr);	//Open socket & for communication

	if(!fp)
	{
		$results = "Error: Could not open socket connection";
	}
	else
	{
		//Writing to file
		fputs ($fp, $login_info[2]."\n");
		fputs ($fp, "en\n");
		fputs ($fp, $login_info[3]."\n");
		fputs ($fp, "config t\n");

		//Read and return output line by line
		fgets ($fp, 1024);					//ÿûÿûÿýÿý
		fgets ($fp, 1024);					//Blank

		$moredetails .= fgets ($fp, 1024);	//User System Verification
		$moredetails .= fgets ($fp, 1024);	//Blank
		$moredetails .= fgets ($fp, 1024);	//telnet pwd
		$moredetails .= fgets ($fp, 1024);	//enable
		$moredetails .= fgets ($fp, 1024);	//enable pwd
		$moredetails .= fgets ($fp, 1024);	//config t
		fgets ($fp, 1024);					//ÿûÿûÿýÿý

		//configure hostname
		fputs ($fp, "hostname ".$_POST['devicename']."\n");		//config hostname command
		$moredetails .= fgets($fp, 1024);				//hostname newhostname

		//exit from config. mode
		fputs ($fp,"exit\n");
		fputs ($fp, "\r");

		$moredetails .= fgets ($fp, 1024);
		$moredetails .= fgets ($fp, 1024);
		$moredetails .= "\n-----------------------------------------------\n\n";
	}
	fclose($fp);

	//store latest info into login_info.txt
	$filename = "Login_Info.txt";
	$store_content = $login_info[0].",".$login_info[1].",".$login_info[2].",".$login_info[3].",".$_POST['devicename'];

	if(is_writeable($filename))
	{
	/*----------------------------------------------------------------------------
		In our example we are opening $filename in append mode.
		The file pointer is at the bottom of the file hence
		that is where $somecontent will go when we fwrite() it.
	----------------------------------------------------------------------------*/
		if (!$handle = fopen($filename, 'w'))
		{
			 echo "Cannot open file ($filename)";
			 exit;
		}
		// Write $somecontent to our opened file.
		if (!fwrite($handle, $store_content))
		{
			echo "Cannot write to file ($filename)";
			exit;
		}
		fclose($handle);
	}
	else
	{
		echo "The file $filename is not writable";
	}
}

//Display info upon entering the page.
$fp = fsockopen($host,$port,$errno,$errstr);

if(!$fp)
{
	$results = "Error: could not open socket connection";
}
else
{
	fputs ($fp, $login_info[2]."\n");		//telnet password
	fputs ($fp, "en\n");					//enable
	fputs ($fp, $login_info[3]."\n");		//secret password
	fputs ($fp, "terminal length 0\n");		//show complete list of info without pausing
	fputs ($fp, "show run\n");				//show run config. command
	fputs ($fp, "\r");						//enter key

	fgets ($fp, 1024);						//ÿûÿûÿýÿý

	while(true)
	{
		$tmpecho = fgets ($fp, 1024);

		//Hide the string of terminal length 0
		if(stristr($tmpecho,'terminal length 0') === FALSE )
		{
			$moredetails .= $tmpecho;
		}

		//break from the loop
		if(substr($tmpecho,'Configuration register is') =='TRUE)
		{
			fputs ($fp, "\r");
			$moredetails .= fgets ($fp, 1024);
			$moredetails .= fgets ($fp, 1024);
			break;
		}
	}
}
fclose($fp);

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>SMART Multi-Vendor Network Deployment System -- CISCO [Aironet 1200 Series]</title>
<link href="../stylesheet/cssStyle.css" rel="stylesheet" type="text/css" />
<script src="../javascript/basicCheck.js"></script>
</head>

<body class="loginCSS">
<center>
<table width="800px" cellpadding="0" cellspacing="0" border="0">
<tr><td><img border="0" src="../assets/images/cisco/cisco1200.gif"></td></tr>
<tr><td><?php include("menu_cisco1200.html"); ?></td></tr>

<tr><td height="20px"></td></tr>

<tr><td align="left">
	<!--CENTER SECTION-->
	<table width="100%" cellpadding="5" cellspacing="5" border="0">

		<!--HEADERS-->
		<tr align="left" valign="top"><td width="70%">
			<strong>G&nbsp;E&nbsp;N&nbsp;E&nbsp;R&nbsp;A&nbsp;L&nbsp;&nbsp;&nbsp;S&nbsp;E&nbsp;T&nbsp;T&nbsp;I&nbsp;N&nbsp;G&nbsp;S</strong>
			<br /><hr size="1">
		</td>
		<td>
			<strong>U&nbsp;S&nbsp;E&nbsp;R&nbsp;&nbsp;&nbsp;A&nbsp;S&nbsp;S&nbsp;I&nbsp;S&nbsp;T&nbsp;A&nbsp;N&nbsp;C&nbsp;E</strong>
			<br><hr size="1">
		</td></tr>

		<!--LEFT COLUMN: DISPLAY INFORMATION & SETTINGS-->
		<tr><td align="center">
			<form name="General" method="post" action="<?php echo $PHP_SELF; ?>" onSubmit="return general_check();">
			<table width="75%" cellpadding="0" cellspacing="0" border="0">

				<!--Display Box-->
				<tr align="center"><td colspan="3">
					<strong>INFORMATION:</strong><br />
					<textarea cols="80" rows="15" readonly><? echo $moredetails; ?></textarea>
				</td></tr>

				<tr><td colspan="3" height="20px"></td></tr>

				<!--SETTINGS FOR CONFIGURATION-->
				<tr align="center"><td colspan="3">
					<strong>SETTINGS:</strong><br />
					<hr size="1">
				</td></tr>

				<!--set hostname-->
				<tr>
					<td valign="top" width="25%"><strong>Host Name</strong></td>
					<td valign="top"><strong>:&nbsp;&nbsp;</strong></td>
					<td valign="top"><input type="text" name="devicename" id="devicename" /></td>
				</tr>

				<tr><td colspan="3" height="20px"></td></tr>

				<!--submit or cancel current configuration-->
				<tr align="center"><td colspan="3">
					<input type="submit" name="submit" id="submit" value="Save" />
					&nbsp;&nbsp;&nbsp;
					<input type="reset" name="cancel" id="cancel" value="Cancel" />
				</td></tr>
			</table>
			</form>
		</td>

		<!--RIGHT COLUMN: INSTRUCTIONS-->
		<td align="left" valign="top">
			[<strong>Hostname</strong>] :
			<br />
			To specify or modify the host name for your network server.
		</td></tr>
	</table>

</td></tr>

<tr><td height="20px"></td></tr>

<!--COPYRIGHT-->
<tr><td align="center"><?php include ("../include/copyright.html") ?></td></tr>

</table>
</center>
</body>
</html> //This is line 226

    thnx.. but i dont find any error like missing of ) or }..

      if anyone dun mind, can someone check d codings 4 me??

        Line 128:

        if(substr($tmpecho,'Configuration register is') =='TRUE)

        missing the closing single quote

          ok.. i closed d single code n i got a new error..

          Fatal error: Maximum execution time of 30 seconds exceeded in C:\Program Files\Apache Group\Apache2\htdocs\Multivendor\cisco1200\General.php on line 122

          This is d line 122:
          if(stristr($tmpecho,'terminal length 0') === FALSE )

            Well that has to do with your telnet reader not shutting down in time. Maybe the remote host isn't disconnecting? Maybe the data is too much?

            You COULD disable that error by adding set_time_limit(0); to the top, but I don't think you want to do that here. It looks as if your fgets() reader is hanging. In this case, the 30 second timeout is what is saving your script from locking up the browser.

            Please be careful here.

              Write a Reply...