Page 2 of 2

Posted: Tue Mar 14, 2006 3:18 pm
by RobertGonzalez
I cleaned up the code you posted a little bit. Every single line had about eight empty (white) spaces at the end of it (even those ones that open and close if statements and the like). There were also some concatenated strings that I cleaned up a bit. See if any of this helps. Just make sure to upload them in ASCII.

Code: Select all

<?php
echo '<body bgcolor="#FFFFFF"><p align="center">';
$pass = is_logged($session_id);
if ($pass == "N") 
{
	include("member_login.html");
}
elseif ($pass =="Y")
{
	$larInfo = get_user_info(get_account_id($session_id),"",false, false);
	echo "<b>Welcome " . $larInfo['acount_primary'] . " " . $larInfo['account_name'] . "! ";
	echo 'You are now logged into your account area. <a href="?page=account&next_page=account&session_id=' . strval($session_id) . '&action=logout"><big>Log Me Out</big></a></b><br>';
	$credits = credit_exsist($account_id);

	if ($credits > 0)
	{
		echo "<br /><b>" . $larInfo['acount_primary'] . ", you have an available account credit of " . setup("currency") . number_format($credits,2) . "</b></p>";
	}
	
	$dba = new ps_DB;
	$q = "SELECT domain_host_id 
		FROM domains 
		WHERE domain_account_id = '$account_id' 
		AND domain_host_status = 1";
  
	$dba->query($q);
	if ($dba->num_rows() > 0)
	{
		echo '<hr size="1" noshade><p><b>Please use your username and password on file to login to the area(s) below that you have subscribed to.</b><br><br>';

		while ( $dba->next_record() )
		{
			$membership_id = $dba->f("domain_host_id");
			$dbz = new ps_DB;
			$q = "SELECT membership_name, membership_directory_id 
				FROM membership 
				WHERE membership_id = '$membership_id'";
			$dbz->query($q);
			$dbz->next_record();
			$directory_id = $dbz->f("membership_directory_id");
			
			if ($directory_id  != 0)
			{
				$dbd = new ps_DB;
				$q = "SELECT directory_url 
					FROM directory 
					WHERE directory_id = '$directory_id'";
				$dbd->query($q);
				$dbd->next_record();
				$directory_url = $dbd->f("directory_url");
				
				echo '
        <table width="100%" border="0" cellspacing="0" cellpadding="2" class="field_t"><tr>
          <td width="20%"><b>' . $dbz->p("membership_name") . '</b></td><td width="49%">
            <a href="http://danceurdc.org/HTML/MEMBERS/Members2hidden.php"><big><big>
            <font color="#0000FF" size="+1" face="Arial, Helvetica, sans-serif"><strong>CLICK
            HERE TO ENTER MEMBERS AREA</strong></font></big></big></a></td></tr>
        </table></b>,<br><hr size="1" noshade>';
			}
		}
	}
	else
	{
		echo '
     <p>Your account does not have any active subscriptions at this point.<br>
      If you have already placed an order, and it shows up below as pending, please
      be patient. We are processing your order and will complete it as soon as possible.<br></p>';
	}
?>

Posted: Tue Mar 14, 2006 4:38 pm
by Michael_C
feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


[quote="Everah"]I cleaned up the code you posted a little bit. Every single line had about eight empty (white) spaces at the end of it (even those ones that open and close if statements and the like). There were also some concatenated strings that I cleaned up a bit. See if any of this helps. Just make sure to upload them in ASCII.
[/quote]

Thanks for taking the time to look at the code and cleaning it up.  Would you think any of the problems you addressed could cause the problems I saw on Sunday?
I didn't worry about cleaning up blank spaces on the right hand of the line of code.  Should I have removed them?  I noticed there are still some blanks at the end of the line - Is it ok?  Preferred?  From the examples I have seen, it didn't look like blank spaces were a problem for the php engine.  My novice eye, or is it just good coding practice?

Is the use of echo instead of echo() preferred?  You changed one echo() function call to the following:

Code: Select all

echo ' 
        <table width="100%" border="0" cellspacing="0" cellpadding="2" class="field_t"><tr>
          <td width="20%"><b>' . $dbz->p("membership_name") . '</b></td><td width="49%">
            <a href="http://danceurdc.org/HTML/MEMBERS/Members2hidden.php"><big><big>
            <font color="#0000FF" size="+1" face="Arial, Helvetica, sans-serif"><strong>CLICK
            HERE TO ENTER MEMBERS AREA</strong></font></big></big></a></td></tr>
        </table></b>,<br><hr size="1" noshade>';
Was there a benefit? Speed?

The following(minus blank lines) is an example of what the code looked like - As I mentioned before, I re-did the code mainly so I could understand what was going on.

Code: Select all

<body bgcolor="#FFFFFF">  	
<p align="center"><b>   	
<?php  	
$pass = is_logged($session_id);  	
if ($pass == "N") {  	
include("member_login.html");  	
} elseif($pass =="Y") {  	
$account_id  = get_account_id($session_id);  	
$db = new ps_DB;  	
$q = "SELECT * FROM account WHERE account_id = '$account_id'";   	
$db->query($q);  	
$db->next_record();  	
$f_name = split(" ",$db->f("account_name"));  	
$f_firstname = split(" ",$db->f("account_firstname"));  	
?>  	
  Welcome   	
    <?  	
  echo $f_firstname [0];  	
  ?>  	
  <?  	
  echo $f_name [0];  	
  ?>  	
  ! You are now logged into your account area. [ <a href="?page=account&next_page=account&session_id=<? echo $session_id ?>&action=logout"><big>Log   	
  Me Out</big></a> ]<br>  	
  <?   	
  $credits    = credit_exsist($account_id);  	
  if($credits > 0) {  	
  echo "<BR>" . $f_name[0];  	
  ?>, you have an available account credit of <? echo setup("currency") . '' . number_format($credits,2); ?>.  	
  <?   	
}  	
  ?>  	
  </b></p>  	
<?    	
    $dba = new ps_DB;  	
  $q = "SELECT domain_host_id FROM domains WHERE   	
      domain_account_id = '$account_id' AND   	
      domain_host_status = '1'";   	
  $dba->query($q);  	
  if ($dba->num_rows() > 0) {  	
?>  	
<hr size="1" noshade>  	
<p><b></b>Please use your username and password on file to login to the area(s)  	
   below that you have subscribed to. <br>  	
  <br>  	
<b>   	
<? while ($dba->next_record()) {  	
  $membership_id = $dba->f("domain_host_id");  	
    $dbz = new ps_DB;  	
  $q = "SELECT membership_name,membership_directory_id FROM membership WHERE membership_id = '$membership_id'";   	
  $dbz->query($q);  	
  $dbz->next_record();  	
  $directory_id = $dbz->f("membership_directory_id");  	
  if ($directory_id  != 0)  	
  {  	
  $dbd = new ps_DB;  	
  $q = "SELECT directory_url FROM directory WHERE directory_id = '$directory_id'";   	
  $dbd->query($q);  	
  $dbd->next_record();  	
  $directory_url = $dbd->f("directory_url");  	
 ?>  	
<table width="100%" border="0" cellspacing="0" cellpadding="2" class="field_t">  	
  <tr>   	
    <td width="20%"> <b>   	
      <? $dbz->p("membership_name"); ?>  	
      </b></td>  	
    <td width="49%"><a href="http://danceurdc.org/HTML/MEMBERS/Members2hidden.php"><big><big><font color="#0000FF" size="+1" face="Arial, Helvetica, sans-serif"><strong>CLICK   	
      HERE TO ENTER MEMBERS AREA</strong></font></big></big></a></td>  	
  </tr>  	
  </table>  	
</b><b>  	
<? } } }  	
else  	
{?>  	
</b>  	
<p>Your account does not have any active subscriptions at this point.   	
  <br>  	
  If you have already placed an order, and it shows up below as pending, please   	
  be patient. We are processing your order and will complete it as soon as possible.<br>  	
  <?}?>

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Tue Mar 14, 2006 5:06 pm
by RobertGonzalez
As far as white space goes, I don't think it is a major concern. The wierd thing is the consistency of it. It looks like the file was being modified as it was placed on the server or something like that (since few developers intentionally add blank spaces at the end of every line). I personally like to code clean so empty spaces like that would annoy the snot out of me.

As for echo, take a look at what the manual says about the parentheses. I don't use them anymore, although when I first started coding PHP I used parentheses all the time on echo.

Looking at the original code, I would have rewritten it from the ground up. I am a stickler about finding a coding standard and adhering to that standard. I personally like the phpBB code standard so I use that one. As a developer you are free to do what you want (unless you are on a project or a team), just try to be consistent with what you are doing.

I think in your case I would probably tend to want to strip away all the empty unneeded spaces and code that thing in an easy to follow standard way. Then upload it, download it and open it to see if there were extra character added. Just to be on the safe side.

Posted: Tue Mar 14, 2006 6:00 pm
by Michael_C
Everah wrote:As far as white space goes, I don't think it is a major concern. The wierd thing is the consistency of it. It looks like the file was being modified as it was placed on the server or something like that (since few developers intentionally add blank spaces at the end of every line). I personally like to code clean so empty spaces like that would annoy the snot out of me.

As for echo, take a look at what the manual says about the parentheses. I don't use them anymore, although when I first started coding PHP I used parentheses all the time on echo.

Looking at the original code, I would have rewritten it from the ground up. I am a stickler about finding a coding standard and adhering to that standard. I personally like the phpBB code standard so I use that one. As a developer you are free to do what you want (unless you are on a project or a team), just try to be consistent with what you are doing.

I think in your case I would probably tend to want to strip away all the empty unneeded spaces and code that thing in an easy to follow standard way. Then upload it, download it and open it to see if there were extra character added. Just to be on the safe side.
Do you know why binary transmission would cause a problem? Doesn't the ftp protocol support error detection and retransmit?

Stripping out the empty spaces is not a problem - I'll just add it to the program that removes the extra blank lines. I will double check if upload process alters the file in any way. The only concern I have is why an error would be generated after stripping out blank lines. I'm a member of the organization who owns the website - it's a freeby. The time to change the code on the site is more than I'm willing to donate - plus I have more problems with the content and organization of the site than the code itself - The only reason I picked on this program is it looked like the write place to hook into what I've signed on to do. Maybe, I'll be back to that shortly.

Thanks again for the primer on php

Posted: Tue Mar 14, 2006 6:10 pm
by RobertGonzalez
Try using this and see if it makes any difference with what your script is doing...

Code: Select all

<body bgcolor="#FFFFFF">
<p align="center"><b>
<?php
$pass = is_logged($session_id);
if ( "N" == $pass ) {
	include("member_login.html");
}
elseif ( "Y" == $pass ) {
	$account_id = get_account_id($session_id);
	$db = new ps_DB;
	$q = "SELECT * 
		FROM account 
		WHERE account_id = '$account_id'";
	$db->query($q);
	$db->next_record();
	$f_name = split(" ", $db->f("account_name"));
	$f_firstname = split(" ", $db->f("account_firstname"));

	echo "Welcome " . $f_firstname[0] . " " . $f_name[0] . "!";
?>
You are now logged into your account area. [ <a href="?page=account&next_page=account&session_id=<?php echo $session_id ?>&action=logout">
<big>Log Me Out</big></a> ]<br />
<?php
	$credits = credit_exsist($account_id);
	if ( $credits > 0 ) {
		echo "<br />" . $f_name[0] . ", you have an available account credit of " . setup("currency") . " " . number_format($credits,2);
	}
  ?>
  </b></p>
<?php
	$dba = new ps_DB;
	$q = "SELECT domain_host_id 
		FROM domains 
		WHERE domain_account_id = '$account_id' 
		AND domain_host_status = 1";
	$dba->query($q);
	if ( $dba->num_rows() > 0 ) {
?>
<hr size="1" noshade>
<p><b></b>Please use your username and password on file to login to the area(s)
   below that you have subscribed to. <br>
  <br>
<b> 
<?php
	while ( $dba->next_record() ) {
		$membership_id = $dba->f("domain_host_id");
		$dbz = new ps_DB;
		$q = "SELECT membership_name, membership_directory_id 
			FROM membership 
			WHERE membership_id = '$membership_id'";
		$dbz->query($q);
		$dbz->next_record();
		$directory_id = $dbz->f("membership_directory_id");
		if ($directory_id  != 0) {
			$dbd = new ps_DB;
			$q = "SELECT directory_url 
				FROM directory 
				WHERE directory_id = '$directory_id'";
				
			$dbd->query($q);
			$dbd->next_record();
			$directory_url = $dbd->f("directory_url");
 ?>
<table width="100%" border="0" cellspacing="0" cellpadding="2" class="field_t">
  <tr> 
    <td width="20%"> <b> 
<?php
			$dbz->p("membership_name"); 
?>
</b></td>
    <td width="49%"><a href="http://danceurdc.org/HTML/MEMBERS/Members2hidden.php"><big><big><font color="#0000FF" size="+1" face="Arial, Helvetica, sans-serif"><strong>CLICK 
HERE TO ENTER MEMBERS AREA</strong></font></big></big></a></td>
  </tr>
  </table>
</b><b>
<?php
		}
	}
}
else
{
?>
</b>
<p>Your account does not have any active subscriptions at this point. 
  <br>
  If you have already placed an order, and it shows up below as pending, please 
  be patient. We are processing your order and will complete it as soon as possible.<br>
<?php
}
?>

Posted: Tue Mar 14, 2006 6:40 pm
by RobertGonzalez
Michael_C wrote:Do you know why binary transmission would cause a problem? Doesn't the ftp protocol support error detection and retransmit?
Read over of this little post. It is not the most informative but it covers something peculiar as it relates to your script.

Posted: Tue Mar 14, 2006 7:28 pm
by Michael_C
Everah wrote:Read over of this little post. It is not the most informative but it covers something peculiar as it relates to your script.
Thanks - good to know - I'll be glad to let the systems handle translations

Posted: Wed Mar 15, 2006 7:52 am
by Benjamin
Jcart wrote:Sounds like there are some hidden characters in the document. Try manually typing them out in a fresh new file (as in DO NOT copy and paste) -- OR -- opening the document in notepad which should show the hidden characters.

Things like this usual occur in software such as Dreamweaver (not sure if it was fixed in Dreamweaver 8, although I have no encountered this in a couple months)
Jcart is dead right on this one. There really isn't any other way to fix it. I have ran into this before while fixing scripts written by others. In my case opening it up in kedit (a Linux text editor) didn't even provide any clues to the problem. I literally had to retype all the code into a new file.

Posted: Wed Mar 15, 2006 11:34 am
by Michael_C
agtlewis wrote:
Jcart wrote:Sounds like there are some hidden characters in the document. Try manually typing them out in a fresh new file (as in DO NOT copy and paste) -- OR -- opening the document in notepad which should show the hidden characters.

Things like this usual occur in software such as Dreamweaver (not sure if it was fixed in Dreamweaver 8, although I have no encountered this in a couple months)
Jcart is dead right on this one. There really isn't any other way to fix it. I have ran into this before while fixing scripts written by others. In my case opening it up in kedit (a Linux text editor) didn't even provide any clues to the problem. I literally had to retype all the code into a new file.
I would think I'd be as likely to introduce errors in that process. I think I would rather opt to write a program to remove any characters below ascii 20 (hex) - with the exception of CR, LF, VT, HT

Any reason that wouldn't work?