1

I'm having a very strange problem with one of my webpages. It's written in PHP and suddenly today, without any changes to the site, it started to freeze while loading a certain page (and this page only). Freezing means that half of the page loads and then it stops and looks like the browser is waiting for some more info from the server (same thing in all popular browsers).

The page has 2 types of users and it works fine for Admin but freezes for User. The only difference is that the User doesn't have radio buttons for rows of the table in certain status. Now, while I was trying to fix this I started with manipulating the code, hoping that I will find the part which causes the problem, but it turns out that I can delete whichever part of the page and the problem disappears. I can also add a line or two and the problem disappears. Being more specific: doesn't work every time. I added one additional line which adds a hidden field to a form and the problem still occured, but I added another one with a different name and now it works.

I'm using PHP "print" function to output each line of code to the browser.

What can cause this problem? It's so strange, that I just have to know! :)

I did some additional testing. Now it works with just one line added. This line is:

print "<input type=\"hidden\" name=\"a\" value=\"123456789012345678901234567890\">";

If I delete one digit from "123456789012345678901234567890" number it starts freezing again! If I add more digits, it still works fine...

There is no javascript code scanning for anything after page loads.

This is the whole code of that page. It's embeded into index.php The biggest question is: why does it work for 'admin' and doesn't work for 'user' (these are fields from the database)

<?
//$gdzie = "noworodki";
$userx = $_SESSION['userx'];
$result2=mysql_query("SELECT * FROM porody_ludzie WHERE login = '$userx'");
$row5=mysql_fetch_array($result2);

$dzisiaj = getdate(); 
$rok     = $dzisiaj['year']; 

$ilosc_rekordow = 15;
$ktora_tabela = "porody_karta";
if(($filter=="Filtruj")||($filter=="filtrowane")){
  if($filter=="Filtruj"){
    $strona=0;
  }
  if($numer_karty!=""){
    $query = mysql_query("SELECT COUNT(*) FROM $ktora_tabela WHERE numer = '$numer_karty'");
  }else{
    if($rodzaj_porodu!="-----"){
      $query = mysql_query("SELECT COUNT(*) FROM $ktora_tabela WHERE rodzaj_p LIKE '$rodzaj_porodu'");
    }else{
      if($status!="-----"){
        $query = mysql_query("SELECT COUNT(*) FROM $ktora_tabela WHERE status = '$status'");
      }else{
        //po nazwisku matki
        if($nazwisko_matki!=""){
          $query = mysql_query("SELECT COUNT(*) FROM $ktora_tabela WHERE nazwisko LIKE '$nazwisko_matki'");
        }else{          
          //print "po all<br>";
          $query = mysql_query("SELECT COUNT(*) FROM $ktora_tabela");
        }
      }
    }
  }
}else{
  $query = mysql_query("SELECT COUNT(*) FROM $ktora_tabela");
}
$ilosc_rekordow_w_tabeli = mysql_result($query, 0, 0); 
$max = ceil($ilosc_rekordow_w_tabeli/$ilosc_rekordow);
if($next=="następna"){
  $strona++;
}elseif($next=="poprzednia"){
  $strona--;
}elseif($next=="pierwsza"){
  $strona=0;
}elseif($next=="ostatnia"){
  if($max>1){
    $strona=$max-1;
  }
}
$offset = $strona*$ilosc_rekordow;
print '<table border=0 width="100%">
      <tr>
        <td width="30%">&#160;</td>
        <td width="10%">';
  print "<form method=\"post\" action=\"index.php\">";
  print "<input type=\"hidden\" name=\"action\" value=\"0\">";
  print "<input type=\"hidden\" name=\"strona\" value=\"$strona\">";    
  print "<input type=\"hidden\" name=\"gdzie\" value=\"$gdzie\">";  
  if($filter!=""){  
    print "<input type=\"hidden\" name=\"filter\" value=\"filtrowane\">";
  }
  print "<input type=\"hidden\" name=\"rodzaj_porodu\" value=\"$rodzaj_porodu\">";
  print "<input type=\"hidden\" name=\"nazwisko_matki\" value=\"$nazwisko_matki\">";
  print "<input type=\"hidden\" name=\"status\" value=\"$status\">";
  print "<input type=\"hidden\" name=\"numer_karty\" value=\"$numer_karty\">";
  print "<center><input type=\"submit\" name=\"next\" value=\"pierwsza\"></form></td>";                     
  print '<td width="10%">';
if($strona>0){
  print "<form method=\"post\" action=\"index.php\">";
  print "<input type=\"hidden\" name=\"action\" value=\"0\">";
  print "<input type=\"hidden\" name=\"strona\" value=\"$strona\">";    
  print "<input type=\"hidden\" name=\"gdzie\" value=\"$gdzie\">";
  if($filter!=""){  
    print "<input type=\"hidden\" name=\"filter\" value=\"filtrowane\">";
  }
  print "<input type=\"hidden\" name=\"rodzaj_porodu\" value=\"$rodzaj_porodu\">";
  print "<input type=\"hidden\" name=\"nazwisko_matki\" value=\"$nazwisko_matki\">";
  print "<input type=\"hidden\" name=\"status\" value=\"$status\">";
  print "<input type=\"hidden\" name=\"numer_karty\" value=\"$numer_karty\">";      
  print "<center><input type=\"submit\" name=\"next\" value=\"poprzednia\"></form>";    
}else{
  print '&#160;';
}
print '</td><td width="10%">';
if($strona<$max-1){
  print "<form method=\"post\" action=\"index.php\">";
  print "<input type=\"hidden\" name=\"action\" value=\"0\">";
  print "<input type=\"hidden\" name=\"strona\" value=\"$strona\">";    
  print "<input type=\"hidden\" name=\"gdzie\" value=\"$gdzie\">";  
  if($filter!=""){  
    print "<input type=\"hidden\" name=\"filter\" value=\"filtrowane\">";
  }
  print "<input type=\"hidden\" name=\"rodzaj_porodu\" value=\"$rodzaj_porodu\">";
  print "<input type=\"hidden\" name=\"nazwisko_matki\" value=\"$nazwisko_matki\">";
  print "<input type=\"hidden\" name=\"status\" value=\"$status\">";
  print "<input type=\"hidden\" name=\"numer_karty\" value=\"$numer_karty\">";          
  print "<center><input type=\"submit\" name=\"next\" value=\"następna\"></form>";  
}else{
  print '&#160;';
}
print '</td><td width="10%">';
print "<form method=\"post\" action=\"index.php\">";
print "<input type=\"hidden\" name=\"action\" value=\"0\">";
print "<input type=\"hidden\" name=\"strona\" value=\"$strona\">";  
print "<input type=\"hidden\" name=\"gdzie\" value=\"$gdzie\">";    
if($filter!=""){    
    print "<input type=\"hidden\" name=\"filter\" value=\"filtrowane\">";
}
print "<input type=\"hidden\" name=\"rodzaj_porodu\" value=\"$rodzaj_porodu\">";
print "<input type=\"hidden\" name=\"nazwisko_matki\" value=\"$nazwisko_matki\">";
print "<input type=\"hidden\" name=\"status\" value=\"$status\">";
print "<input type=\"hidden\" name=\"numer_karty\" value=\"$numer_karty\">";    
print "<center><input type=\"submit\" name=\"next\" value=\"ostatnia\"></form></td>";                       
print '<td width="30%">&#160;</td></tr></table>';

$strona++;

  print "<form name=\"ludzie\" method=\"post\" action=\"index.php\">";
  print "<table border=0 width=\"100%\">
      <tr>
        <td width=\"15%\">
          <font size=\"-1\">Numer strony: $strona</font><br>";
  $strona--;
  print "       </td>
        <td width=\"25%\">
          <font size=\"-1\">Status: <br>
          <select id=\"status\" name=\"status\">";  

    print "<option>-----</option>";
    print "<option>otwarty</option>";
    print "<option>zamknięty</option>";

    print "</select>
        </td>
        <td width=\"20%\">
          <font size=\"-1\">Numer karty: <br><input name=\"numer_karty\">
        </td>
        <td width=\"20%\">
          <font size=\"-1\">Rodzaj porodu: <br>";
        print "<select name=\"rodzaj_porodu\" id=\"rodzaj_porodu\">";
        print "<option>-----</option>";
        $rodzajPoroduResult=mysql_query("SELECT * FROM porody_rodzaje_porodow");
        while($rodzajPoroduRow=mysql_fetch_array($rodzajPoroduResult)){
          print "<option value=\"$rodzajPoroduRow[id]\">$rodzajPoroduRow[nazwa]</option>";
        }
        print "</select>";
        print "</td>
        <td width=\"20%\">
          <font size=\"-1\">Nazwisko matki: <br><input name=\"nazwisko_matki\" id=\"nazwisko_matki\">
        </td>
        <td width=\"5%\">";
          print "<input type=\"hidden\" name=\"action\" value=\"0\">";              
          print "<input type=\"hidden\" name=\"gdzie\" value=\"$gdzie\">";
          print "<input type=\"hidden\" name=\"strona\" value=\"$strona\">
          <input type=\"submit\" name=\"filter\" value=\"Filtruj\"></form>
        </td>
    </table>";


print "<form method=\"post\" action=\"index.php\">
<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" valign=\"top\">";

$result2 = "";

if(($filter=="Filtruj")||($filter=="filtrowane")){
  if($numer_karty!=""){
    $result2=mysql_query("SELECT * FROM $ktora_tabela WHERE numer = '$numer_karty' ORDER BY numer DESC LIMIT $offset,$ilosc_rekordow");
  }else{
    if($rodzaj_porodu!="-----"){
      $result2=mysql_query("SELECT * FROM $ktora_tabela WHERE rodzaj_p LIKE '$rodzaj_porodu' ORDER BY numer DESC LIMIT $offset,$ilosc_rekordow");
    }else{

      if($status!="-----"){
        $result2 = mysql_query("SELECT * FROM $ktora_tabela WHERE status = '$status' ORDER BY numer DESC LIMIT $offset,$ilosc_rekordow");
      }else{
        if($nazwisko_matki!=""){
          $result2=mysql_query("SELECT * FROM $ktora_tabela WHERE nazwisko LIKE '$nazwisko_matki' ORDER BY numer DESC LIMIT $offset,$ilosc_rekordow");
        }else{
          //print "po all<br>";
          $result2 = mysql_query("SELECT * FROM $ktora_tabela ORDER BY numer DESC LIMIT $offset,$ilosc_rekordow");
        }
      }
    }
  }
}else{
  $result2=mysql_query("SELECT * FROM $ktora_tabela ORDER BY rok DESC, numer DESC LIMIT $offset,$ilosc_rekordow");
}



print "<tr><td border=\"0\" valign=\"top\" width=\"2%\"><center>#</center></td>";
print "<td border=\"0\" valign=\"top\" width=\"20%\"><b><center>Numer</center></b></td>";
print "<td border=\"0\" valign=\"top\" width=\"15%\"><b><center>Data porodu</center></b></td>";     
print "<td border=\"0\" valign=\"top\" width=\"23%\"><b><center>Imię i nazwisko pacjentki</center></b></td>";   
print "<td border=\"0\" valign=\"top\" width=\"30%\"><b><center>Rodzaj porodu</center></b></td>";       
print "<td border=\"0\" valign=\"top\" width=\"20%\"><b><center>Status</center></b></td></tr>";     

$user=0;
if($_SESSION['userx']!=""){
  $login = $_SESSION['userx'];
  $result4=mysql_query("SELECT * FROM porody_ludzie WHERE login = '$login'");
  $row4=mysql_fetch_array($result4);
  if($row4['status']=="user"){
    $user=1;
  }
}

while($row3=mysql_fetch_array($result2))
{
  $dzisiaj = getdate(); 
  $rok     = $dzisiaj['year']; 
  print "<tr><td align=\"center\">";
  if(($row3['status']!="otwarty")&&($user==1)){
    print '&nbsp;';
  }else{
    print "<INPUT TYPE=\"radio\" NAME=\"ludzie\" VALUE=\"$row3[id]\">";         
  }
  print "</td>";
  print "<td><center><font size=\"-1\"><a href=\"szczegoly.php?gdzie=$gdzie&&rekord=$row3[id]\" target=\"_blank\"><font color=\"black\">
  $row3[numer]/$row3[rok] BI</font></a></font></center></td>";                      
  print "<td><center><font size=\"-1\">$row3[data_por]</font></center></td>";
  print "<td><center><font size=\"-1\">$row3[imie] $row3[nazwisko]</font></center></td>";
  $rodzajPoroduResult=mysql_query("SELECT * FROM porody_rodzaje_porodow WHERE id = '$row3[rodzaj_p]'");
  $rodzajPoroduRow=mysql_fetch_array($rodzajPoroduResult);
  if($rodzajPoroduRow[nazwa]==""){
    $rodzajPoroduRow[nazwa] = "---";
  }
  print "<td><center><font size=\"-1\">$rodzajPoroduRow[nazwa]</font></center></td>";       
  print "<td";
  if($row3[status]=="otwarty"){
    print ' bgcolor="yellow"';
  }elseif($row3[status]=="zamknięty"){
    print ' bgcolor="green"';       
  }
  print "><center><font size=\"-1\">$row3[status]</font></center></td>";        
  print "</tr>";
}
print "</table><br>";
print "<input type=\"hidden\" name=\"action\" value=\"61\">";
print "<input type=\"hidden\" name=\"gdzie\" value=\"$gdzie\">";
print "<input type=\"hidden\" name=\"strona\" value=\"$strona\">";          
print "<center><input type=\"submit\" name=\"ok\" value=\"Edytuj\">";   
print "<input type=\"submit\" name=\"ok\" value=\"Kasuj\">";        
print "<input type=\"submit\" name=\"ok\" value=\"Dodaj\">";        
print "<center><input type=\"submit\" name=\"ok\" value=\"Zmień status\"></center>";                
print "<input type=\"hidden\" name=\"a\" value=\"1234567890123456789012345678901234567890\">";

print "</form>";        

?>
Ry-
  • 218,210
  • 55
  • 464
  • 476
  • Define "freeze"? Prints half a page and stops? Prints half a page and the browser spins on downloading forever? Have you checked your error logs? Have you looked at the page source? My guess: PHP is doing fine but improper output escaping combined with someone entering a `<` in a field somewhere is causing the browser to think a major chunk of a page is inside of an unknown tag, which explains why changing the structure of the page works. – DerfK Jul 20 '12 at 13:13
  • Freezing means that the page stops after loading half of it and then spins on downloading (not forever, but for 2-3 mins and after that it loads properly). –  Jul 20 '12 at 13:36
  • I've never used any error logs. Can you name a tool I can check that with? –  Jul 20 '12 at 13:38
  • Damn enter doesn't work :P I'll look gain for some additional < but since I didn't change anything in the page before it started to crash... that's strange... –  Jul 20 '12 at 13:39
  • Perhaps turning [output buffering](http://stackoverflow.com/a/2832179/1159643) **on** might make a difference? See [here](http://php.net/manual/en/outcontrol.configuration.php) for information on turning it on. – Spooky Jul 20 '12 at 14:36

3 Answers3

0

Not sure if what you have posted causes the issue (considering you haven't posted all the code, other things like missing semi-colons or quotes could cause issues, along with we don't know if you ever close the input field).

Try this:

echo "<input type='hidden' name='a' value='123456789012345678901234567890'>";

I changed out the escaped quotes because escaping things can cause problems depending on where you are testing your code (IE if you test short code using a website they double escape back slashes). Also changed print to echo since echo is a little faster and if you get use to using print and move to a language that uses that to actually print (to printer) it gets confusing.

Event_Horizon
  • 708
  • 1
  • 11
  • 30
0

Do you have jquery or some kind of javascript that is scanning the page after it has loaded. I have seen where a javascript function could lockup the browser if there is a bug somewhere.

Richard Dev
  • 1,110
  • 7
  • 21
0

Output buffering is the cause. I reinstalled IIS and php on a development server trying to solve this and output buffering was set to 4096. I changed this to On in the php.ini file and it worked fine. After each table or block of divs it is best to use ob_flush(); and flush(); as then users will see the page loading. Without this in some browsers it will output all the code to browser in one chunk so a large page will takes before a users sees anything

Dave
  • 1