Begging PHP, length of message | | |
My guestbook brekas down if the message is to long. The method is
POST, can it still be limits in the length of the message?
Gerry
The code:
<?php
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
?>
<p><pre>
</pre>
<form method="post" action="store.php3">
<span class="text"> Meddelande:</span><br>
<TextArea name="meddel" rows=5 cols=50></TextArea><br>
<span class="text"> Namn:</span><br>
<input type="Text" name="namn"></input><br>
<input type="Submit" name="submit" value="Skicka"></input>
</form>
<?
// ------ Editera dessa! --------------
$persida=10; // Antal inlägg som skall visas per sida.
$noprev="noprev.gif"; // Sökväk till deaktiverad föregångar-knapp.
$nonext="nonext.gif"; // Sökväg till deaktiverad nästa-knapp.
$prev="prev.gif"; // Sökväg till föregångar-knapp.
$next="next.gif"; // Sökväg till nästa-knapp.
// ------------------------------------
$sidor=0;
$storlek=0;
$namn="";
$epost="";
$meddelande="";
$titel="";
$hemsida="";
$sidnr=1;
$ipnr="";
$tidp="";
$datum="";
function initiera(){
// Initiering av de komponenter som behövs. Körs alltid först!
global $sidor, $persida, $namn, $epost, $meddelande, $hemsida, $titel,
$storlek, $start, $sidnr,
$ipnr, $tidp, $datum;
// Läs i fil antalet inlägg i gästboken
if(!($fpread = fopen("inlagg.txt", 'r'))){
$fpwrite = fopen("inlagg.txt", 'w');
fputs($fpwrite,"0\n");
fclose($fpwrite);
$sidor=1;
$storlek=0;
}else{
$storlek=fgets($fpread,1024);
$sidnr=floor($start/$persida)+1;
// Beräkna hur många sidor dessa inlägg tar
$sidor=ceil($storlek/$persida);
if($sidor==0) $sidor=1;
// Läser igenom dagboksfil en och lagrar inlägg som skall visas på
denna sida
$mess=0;
$index=0;
while(!feof($fpread)){
$data1=fgets($fpread,200);
$data2=fgets($fpread,200);
$data3=fgets($fpread,200);
$data4=fgets($fpread,200);
$data5=fgets($fpread,2020);
$data6=fgets($fpread,1024);
$tom=fgets($fpread,1024);
if($mess>=$start && $mess<$start+$persida){
$namn[$index]=$data1;
$epost[$index]=$data2;
$hemsida[$index]=$data3;
$titel[$index]=$data4;
$meddelande[$index]=$data5;
list($ipnr[$index],$datum[$index],$a,$b,$c)=explode(":",$data6);
$tidp[$index]="$a:$b";
$index=$index+1;
}
$mess++;
}
}
}
function visa_nav(){
global $start,$persida,$storlek,$sidor,$sidnr;
echo "::: ";
for($i=1;$i<=$sidor;$i++)
if($i==$sidnr)
echo "<a href=\"$PHP_SELF?start=".($i-1)*$persida."\"><b>$i</b></a>
::: ";
else
echo "<a href=\"$PHP_SELF?start=".($i-1)*$persida."\">$i</a> ::: ";
}
function visa_nav_framat(){
// Visar navigeringsknapp för "nästa"
global $start, $sidor, $persida, $storlek;
global $next, $nonext;
if($start+$persida<$storlek){
$newpage=$start+$persida;
echo "<a href=\"$PHP_SELF?start=$newpage\"><img src=\"".$next."\"
border=\"0\"></a>";
}else{
echo "<img src=\"".$nonext."\">";
}
}
function visa_nav_bakat(){
// Visar navigeringsknapp för "föregående"
global $start, $sidor, $persida, $storlek;
global $prev, $noprev;
if($start>=$persida){
$newpage=$start-$persida;
echo "<a href=\"$PHP_SELF?start=$newpage\"><img src=\"".$prev."\"
border=\"0\"></a>";
}else{
echo "<img src=\"".$noprev."\">";
}
}
function visa_antal_meddelanden(){
global $storlek;
echo $storlek;
}
function visa_antal_sidor(){
global $sidor;
echo $sidor;
}
function visa_sidnr(){
global $sidnr;
echo $sidnr;
}
function visa_meddelande($index){
global $namn, $epost, $meddelande, $hemsida, $titel, $start, $storlek,
$persida, $sidor, $ipnr,
$tidp, $datum;
$sidan=floor($start/$persida)+1;
$limit=$persida;
if(($sidan==$sidor) && ($storlek % $persida)>0)
$limit=$storlek%$persida;
if($index<$limit && $storlek>0){
//////////////////////////////////////////////////////////////
echo "
Datum: <i>$datum[$index]</i> Klockan <i>$tidp[$index]</i><br>
Namn: <b>$namn[$index]</b></font><br>
<font color='black'>$meddelande[$index]</font><br><br><hr>
";
///////////////////////////////////////////////////////////////
}
}
?>
<! ----------------------------------------------- !>
<html>
<head>
<title>Bilder</title>
</head>
<! Utför initiera först !>
<?initiera();?>
<center>
<br>
<?visa_nav();?><br>
Det finns <?visa_antal_meddelanden();?> meddelanden på
<?visa_antal_sidor();?> sidor. Detta är
sida <?visa_sidnr();?>.
</center>
<br>
<hr>
<! Visa alla inläggen på sidan !>
<?
for($i=0;$i<=$persida;$i++)
visa_meddelande($i);
?>
<tr>
<td>
</body>
</html> | | | | re: Begging PHP, length of message
Gerry N wrote:[color=blue]
>
> My guestbook brekas down if the message is to long. The method is
> POST, can it still be limits in the length of the message?[/color]
There are limits to the amount of text that can go in form elements, depending
on the browser. What browser are you using to test and how long is too long?
You might want to start by determining the exact character length, if it's
constant.
You might also want to try tracking down the error by printing the value at
different points in the script. Usually, you won't get a good response in this
group if you post an entire script, especially if it's in a language other than
English. Most people here like to look at small snippets of code and only the
code where you believe the error to be originating.
Regards,
Shawn
--
Shawn Wilson shawn@glassgiant.com http://www.glassgiant.com
I have a spam filter. Please include "PHP" in the
subject line to ensure I'll get your message. | | | | re: Begging PHP, length of message
On Thu, 15 Jan 2004 10:11:16 -0400, Shawn Wilson
<shawn@glassgiant.com> wrote:
[color=blue]
>Gerry N wrote:[color=green]
>>
>> My guestbook brekas down if the message is to long. The method is
>> POST, can it still be limits in the length of the message?[/color]
>
>There are limits to the amount of text that can go in form elements, depending
>on the browser. What browser are you using to test and how long is too long?
>You might want to start by determining the exact character length, if it's
>constant.
>
>You might also want to try tracking down the error by printing the value at
>different points in the script. Usually, you won't get a good response in this
>group if you post an entire script, especially if it's in a language other than
>English. Most people here like to look at small snippets of code and only the
>code where you believe the error to be originating.
>
>Regards,
>Shawn[/color]
Toio long is maybe a bit less than an A4 full written. The browser is
IE 6, it doesn't seem important to the problem as it occur in all
browsers.
A snippet af the code that I as a beginner in this, coluld suspect
some problem is here:
$mess=0;
$index=0;
while(!feof($fpread)){
$data1=fgets($fpread,200);
$data2=fgets($fpread,200);
$data3=fgets($fpread,200);
$data4=fgets($fpread,200);
$data5=fgets($fpread,2020);
$data6=fgets($fpread,1024);
$tom=fgets($fpread,1024);
if($mess>=$start && $mess<$start+$persida){
$namn[$index]=$data1;
$epost[$index]=$data2;
$hemsida[$index]=$data3;
$titel[$index]=$data4;
$meddelande[$index]=$data5;
list($ipnr[$index],$datum[$index],$a,$b,$c)=explode(":",$data6);
$tidp[$index]="$a:$b";
Any clue?
Gerry | | | | re: Begging PHP, length of message
Gerry N wrote:[color=blue]
>
> On Thu, 15 Jan 2004 10:11:16 -0400, Shawn Wilson
> <shawn@glassgiant.com> wrote:
>[color=green]
> >Gerry N wrote:[color=darkred]
> >>
> >> My guestbook brekas down if the message is to long. The method is
> >> POST, can it still be limits in the length of the message?[/color]
> >
> >There are limits to the amount of text that can go in form elements, depending
> >on the browser. What browser are you using to test and how long is too long?
> >You might want to start by determining the exact character length, if it's
> >constant.
> >
> >You might also want to try tracking down the error by printing the value at
> >different points in the script. Usually, you won't get a good response in this
> >group if you post an entire script, especially if it's in a language other than
> >English. Most people here like to look at small snippets of code and only the
> >code where you believe the error to be originating.
> >
> >Regards,
> >Shawn[/color]
>
> Toio long is maybe a bit less than an A4 full written. The browser is
> IE 6, it doesn't seem important to the problem as it occur in all
> browsers.
> A snippet af the code that I as a beginner in this, coluld suspect
> some problem is here:[/color]
<SNIP>[color=blue]
>
> Any clue?[/color]
I find that code really hard to read. My best guess (without reading the code
line by line) is that it's cutting off after a newline of after the 1024 bytes
mentioned in the fgets. I would count the characters (actually, just use strlen
instead of counting). See if the length conforms to the 1024 or 2020
characters. Also, does it always end on a newline or will it cut off mid-word?
Answering those questions might give you a clue.
Is the whole entry being written to the text file?
Could you give an example of the text file you're storing the text in?
Regards,
Shawn
--
Shawn Wilson shawn@glassgiant.com http://www.glassgiant.com
I have a spam filter. Please include "PHP" in the
subject line to ensure I'll get your message. | | | | re: Begging PHP, length of message
[color=blue][color=green]
>>
>> Any clue?[/color]
>
>I find that code really hard to read. My best guess (without reading the code
>line by line) is that it's cutting off after a newline of after the 1024 bytes
>mentioned in the fgets. I would count the characters (actually, just use strlen
>instead of counting). See if the length conforms to the 1024 or 2020
>characters. Also, does it always end on a newline or will it cut off mid-word?
>
>Answering those questions might give you a clue.
>
>Is the whole entry being written to the text file?
>
>Could you give an example of the text file you're storing the text in?
>[/color]
Changing the 1024 doesn't make any different but the changing of the
2020 number did the job. Though, where does the 2020 come from???
Doesn't seem to fit in the digital world!?
Gerry | | | | re: Begging PHP, length of message
Gerry N wrote:[color=blue]
>[color=green][color=darkred]
> >>
> >> Any clue?[/color]
> >
> >I find that code really hard to read. My best guess (without reading the code
> >line by line) is that it's cutting off after a newline of after the 1024 bytes
> >mentioned in the fgets. I would count the characters (actually, just use strlen
> >instead of counting). See if the length conforms to the 1024 or 2020
> >characters. Also, does it always end on a newline or will it cut off mid-word?
> >
> >Answering those questions might give you a clue.
> >
> >Is the whole entry being written to the text file?
> >
> >Could you give an example of the text file you're storing the text in?
> >[/color]
>
> Changing the 1024 doesn't make any different but the changing of the
> 2020 number did the job. Though, where does the 2020 come from???
> Doesn't seem to fit in the digital world!?[/color]
It is an strange number. I don't know why they would have chosen it.
Regards,
Shawn
--
Shawn Wilson shawn@glassgiant.com http://www.glassgiant.com
I have a spam filter. Please include "PHP" in the
subject line to ensure I'll get your message. |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,510 network members.
|