Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> KISGB General Support
Author Message
markus
New Member
New Member



Joined: Aug 06, 2002
Posts: 5

PostPosted: Tue Mar 30, 2004 12:47 pm Reply with quote

Hello,

the people hosting our webserver just installed an addiditonal XML feature to php. The version they are running is PHP 4.3.5.

I am able to use the guestbook, but old entries appear truncated, only the last line of the entered comment is displayed. This happens with new entries too. I copied the kisgb.php.csv file to my home environment (PHP 4.3.1) and it works fine - the whole comment appears.
I sure that I installed on both machines the same kisgb files, only some minor changes in user.prefs.php (home-link and password).

I have seen from the PHP documentation that some functions changed, so does anyone know about the problem?

If you need more info about the server config. I can inclcude the phpinfo output.

Thanks for helping, we at Kim-Dojo like the guest book! Question

Markus
 
View user's profile Send private message Visit poster's website
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Tue Mar 30, 2004 5:07 pm Reply with quote

Thanks for the heads up. I have 4.3.5 but haven't installed it yet. It seems I saw this behaviour in an earlier version and it was a PHP error and I had to install a work around. Don't know if it's the same thing or not. I'll let you know.
 
View user's profile Send private message
Raven







PostPosted: Wed Mar 31, 2004 12:01 am Reply with quote

I just tested this under 4.3.5 and I have no problems at all. Please email me the phpinfo output, or better yet, PM me the link to the phpinfo program so I can just look online. What version of KISGB are you using? What version of nuke? Could you zip up your entire kisgb-nuke folder and send it to me so I can try to replicate the error?
 
markus







PostPosted: Sat Apr 03, 2004 5:04 am Reply with quote

Hi again,
I did some debugging and found the following:

The kisgb.php file is parsed with the fgetcsv function. After the function call, the $data array contains only the last line of the comment in the kisgb.php file.

I'm quite sure that the problem lies in a different behaviour of fgetcsv and its treatment of \r\n or \n respectively. Strange enough, opening the file in plaine binary (b) or windows-translation mode (t) did not help.

Here the comments from the fopen command from the php doc:

Note: Different operating system families have different line-ending conventions. When you write a text file and want to insert a line break, you need to use the correct line-ending character(s) for your operating system. Unix based systems use \n as the line ending character, Windows based systems use \r\n as the line ending characters and Macintosh based systems use \r as the line ending character.

If you use the wrong line ending characters when writing your files, you might find that other applications that open those files will "look funny".

Windows offers a text-mode translation flag ('t') which will transparently translate \n to \r\n when working with the file. In contrast, you can also use 'b' to force binary mode, which will not translate your data. To use these flags, specify either 'b' or 't' as the last character of the mode parameter.

The default translation mode depends on the SAPI and version of PHP that you are using, so you are encouraged to always specify the appropriate flag for portability reasons. You should use the 't' mode if you are working with plain-text files and you use \n to delimit your line endings in your script, but expect your files to be readable with applications such as notepad. You should use the 'b' in all other cases.

If you do not specify the 'b' flag when working with binary files, you may experience strange problems with your data, including broken image files and strange problems with \r\n characters.

For portability, it is strongly recommended that you always use the 'b' flag when opening files with fopen().

Again, for portability, it is also strongly recommended that you re-write code that uses or relies upon the 't' mode so that it uses the correct line endings and 'b' mode instead.

As of PHP 4.3.2, the default mode is set to binary for all platforms that distinguish between binary and text mode. If you are having problems with your scripts after upgrading, try using the 't' flag as a workaround until you have made your script more portable as mentioned above.

Maybe this will be of help in solving the problem
 
Raven







PostPosted: Sat Apr 03, 2004 9:07 am Reply with quote

As I said, I have no problems on windows, nor on linux. If fopen or some other function was the inherent problem, then ALL entries would be wrong, not just some. They all have the same line ending. I cannot [yet] determine what the problem is.
 
markus







PostPosted: Sat Apr 03, 2004 11:47 am Reply with quote

Hello,

I don't agree. There is a difference in the entries appearing and the ones not appearing: The entries appearing consist of one line of text, ended by a newline.

The entries missing consist of several lines, each ending with newline. IMHO that makes a difference. And if after the parsing with fgetcsv entries contained in the file appear truncated in the fgetcsv result array, there is something wrong, at least on my server machine.

But of course I admit that the problem still might be dependent on the way PHP was set up on a server macheine. The php folks btw. released already PHP 4.3.6, including some minor fixes. Maybe we just have to wait until someone else has the same problem.

Regards Markus
 
Raven







PostPosted: Sat Apr 03, 2004 11:58 am Reply with quote

markus wrote:
Hello,

I don't agree. There is a difference in the entries appearing and the ones not appearing: The entries appearing consist of one line of text, ended by a newline.

The entries missing consist of several lines, each ending with newline. IMHO that makes a difference. And if after the parsing with fgetcsv entries contained in the file appear truncated in the fgetcsv result array, there is something wrong, at least on my server machine.

But of course I admit that the problem still might be dependent on the way PHP was set up on a server macheine. The php folks btw. released already PHP 4.3.6, including some minor fixes. Maybe we just have to wait until someone else has the same problem.

Regards Markus
Markus,

Whether you agree or not is irrellevant. I have tested on both windows and linux and it works on both. As I said, I will continue to look into the matter. I am not here to debate conjecture. I offer free scripts with free support. If you have a better understanding, or you think you do, then simply translate that into coding and see if it helps. I have emailed you a link to my linux server running php 4.3.5 using your kisgb file and configuration. As you can see it's working correctly. I would suspect a problem in the configuration of the changes that your host made, but that's just a guess at this point. Or have them install 4.3.6RC1 to see if that fixes it.
 
markus







PostPosted: Sun Apr 04, 2004 3:00 am Reply with quote

Good morning Raven,

again thanks for your help and work.

I will investigate the "case" further. I will talk to the people maintaining our server. I wrote a little test program, which reproduces the described problem.

Maybe this little script is of use to you and other kisgb users if they encounter the same problem.

<?php
$fn = tempnam( '/tmp', 'testfile' );
if( $fp = fopen( $fn, 'w' ) )
{
fwrite( $fp, "\"one\",\"a\nline\nwith\nlinebreaks\n\"" );
fclose($fp);
$fp = fopen($fn, "r");
$row = 1;
while (($data = fgetcsv($fp, 10000, ",")) !== FALSE)
{
$num = count($data);
echo "<p> $num fields in line $row: <br />\n";
$row++;
for ($c=0; $c < $num; $c++)
{
echo $data[$c] . "<br />\n";
}
}
fclose($fp);
}
?>

Expected Output:

<p> 2 fields in line 1: <br />
one<br />
a
line
with
linebreaks
<br />


"Wrong" output:

<p> 2 fields in line 1: <br />
one<br />
<br />



Have a nice sunday!
 
Nukeum66
Life Cycles Becoming CPU Cycles



Joined: Jul 30, 2003
Posts: 551
Location: Neurotic, State, USA

PostPosted: Sun Apr 04, 2004 6:04 am Reply with quote

I'm running Kisgb V5.02 with PHP 4.3.5, no problems at all.

_________________
Scott Johnson MIS Ubuntu/Linux 11.10 
View user's profile Send private message Visit poster's website
Raven







PostPosted: Sun Apr 04, 2004 6:22 am Reply with quote

I tried your script under PHP 4.3.5 for windows and got this
Code:
2 fields in line 1: 

one
a line with linebreaks

I then tried in under PHP 4.3.5 for Linux and got this
Code:
2 fields in line 1: 

one
a line with linebreaks

But, the display is NOT wrong - your code is Smile. \n will never display a line break in a browser. You must TRANSLATE the \n (newline) to <br /> using nl2br for it to display properly. So, your code should read this
Code:
         for ($c=0; $c < $num; $c++)

         {
            echo nl2br($data[$c]) . "<br />\n";
         }
which displays
Code:
2 fields in line 1: 

one
a
line
with
linebreaks
which is the correct PHP code and correctly displays the file. There still is no error here that I can see.
 
markus







PostPosted: Sun Apr 18, 2004 1:54 pm Reply with quote

The people running our website run a FreeBSD Unix OS and use the php ports form the BSD freshports site. http://www.freshports.org/lang/php4/

They upgraded now from version 4.3.5 to version 4.3.6 and fgetcsv and KISGB work again on FreeBSD distributions.


I am happy to bring this news and I want to thank Raven again for his work.

Regards

Markus
 
Raven







PostPosted: Sun Apr 18, 2004 3:12 pm Reply with quote

That is great to hear!
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> KISGB General Support

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©