Jump to content

Question/Help on using echo for DEBUGGING


newbie01.php

Recommended Posts

HI all.

 

I am having problem populating an option box so I inserted some echo commands within the php script, but I can't see the output from the echo commands that am expecting to see on the web page. Can someone please help on why this is not working or whether it should or should not be working? The two echo lines in question are as below:

 

echo 'filename : ' . $filename;

echo 'tnsfile : ' . $tnsfile;

 

The filename extension is .html, does it matter and I should change it to a .php?

 

When I changed the filename extension to .php, the echo commands work and I can see the output of the echo commands but it still does not populate the option box.

 

FYI, I copied this code from an existing Apache-PHP install from another server, that one is PHP5 and am trying to get this running on PHP 4. The original one is working alright with the .html extension, that is, it is populating the option box correctly. So I suppose that eliminates the filename extension as the problem. Does it mean it is because of the PHP version?

 

Any response and feedback will be very much appreciated. Thanks in advance.

 

Complete codes below:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Oracle Login - TEST</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">@import url(calendar-green.css);</style>
<script type="text/javascript" src="jscalendar-1.0/calendar.js"></script>
<script type="text/javascript" src="jscalendar-1.0/lang/calendar-en.js"></script>
<script type="text/javascript" src="jscalendar-1.0/calendar-setup.js"></script>
</head>

<body>
<form id="loginForm" name="loginForm" method="POST" action="main.php?ref=0">

<p><strong></strong></p>
<table width="100%" border="0">
  <tr> 
    <td align="center"><strong><font color="#FF0000" size="6" face="Arial, Helvetica, sans-serif">ORACLE LOGIN TEST PAGE</font></strong></td>
  </tr>
  <tr> 
    <td align="center"><font color="#FF0000" face="Arial, Helvetica, sans-serif"><strong>LOGIN 
      PAGE</strong></font></td>
  </tr>
  <tr>
    <td align="center"> </td>
  </tr>
  <tr>
    <td align="center"><table width="100%" border="0" align="center">
          <tr> 
            <td width="44%"> </td>
            <td width="56%"><font color="#FF0000" face="Arial, Helvetica, sans-serif"> </font></td>
          </tr>
          <tr> 
            <td align="right">USERNAME</td>
            <td align="left"><input type="text" name="username" width="150" /></td>
          </tr>
          <tr> 
            <td align="right">PASSWORD</td>
            <td align="left"><input type="password" name="password" width="150" /></td>
          </tr>
          <tr> 
            <td align="right">ORACLE SERVICE</td>
            <td align="left"><select name="sid">

<?php

// Kill any previous session.
if (isset($_COOKIE[session_name()])) {
    setcookie(session_name(), '', time()-42000, '/');
}

// Finally, destroy the session.
session_destroy();

$filename='C:\oracle\product\10.2.0\db_1\NETWORK\ADMIN\tnsnames.ora';
$tnsfile=file_get_contents($filename);
echo 'filename : ' . $filename;
echo 'tnsfile : ' . $tnsfile;
$count=0;
$stline=0;
$lbrk_count=0;
$rbrk_count=0;
$pos=0;
$trail=0;
$tmpstr="";
$line = explode(PHP_EOL,$tnsfile);

   foreach ($line as $tns) {
      $str=str_replace(' ','',$tns);
  $comm=substr_count($str,'#');
  if ($comm == 0 and strlen($str) != 0 ) {
     $tmpstr=$tmpstr . $str;
         $lbrk_count=substr_count($str,"(");
	 $rbrk_count=substr_count($str,")");
     if ($lbrk_count>0 or $rbrk_count>0) {
	    $trail=$trail+$lbrk_count-$rbrk_count;
		if ($trail==0) {
		   $trail=0;
		   $pos=strpos($tmpstr,"=");
		   echo '<option value=' . substr($tmpstr,0,$pos) .'>' . substr($tmpstr,0,$pos) . '</option>';
		   $tmpstr="";
		}
	 }
   }
   $count++;
   }
// echo $count;
?>
              </select>
</td>
          </tr>
          <tr> 
            <td> </td>
            <td align="left"><input name="submit" type="submit" value="Login" /></td>
          </tr>
          <tr> 
            <td colspan="2"><font size="2">This page is to test Oracle login.</font></td>
          </tr>
        </table></td>
  </tr>
</table>
<p><strong><font color="#FF0000" size="6" face="Arial, Helvetica, sans-serif"></font></strong></p>

</form> 
</body>
</html>

 

Sample entries from the $tnsfile:

 

TESTDB01 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (COMMUNITY = world)(PROTOCOL = TCP)(HOST = TEST01)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SID = TEST01)
    )
  )

TESTDB02 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (COMMUNITY = world)(PROTOCOL = TCP)(HOST = TEST01)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SID = TEST02)
    )
  )

TESTDB03 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (COMMUNITY = world)(PROTOCOL = TCP)(HOST = TEST01)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SID = TEST03)
    )
  )

 

The expected entries of the option box is supposedly TESTDB01, TESTDB02, TESTDB04.

 

 

 

 

I have not tested it but I would suspect that you cant explode using a DEFINE as a delimiter.

$line = explode(PHP_EOL,$tnsfile);

Anyways, what you are doing is not really right. Just use file() and get the contents into an array instead of reading a file into a string and then exploding a string to an array.

 

 

HTH

Teamatomic

 

 

 

 

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.