Ver Mensaje Individual
  #6 (permalink)  
Antiguo 16/03/2010, 17:15
Avatar de reborn
reborn
 
Fecha de Ingreso: febrero-2010
Mensajes: 440
Antigüedad: 14 años, 2 meses
Puntos: 1
Respuesta: Problemas al visualizar archivos en diferentes navegadores.

Ahi cambia el metodo de preguntador/contestador, el q es el adecuado para el foro. No se cual te parecio mi actitud, no lo dije con tono de agresividad ni falta de respeto, lo q menos quiero es crear discordia con la gente del foro.

Bien, ese es el codigo q muestra una noticia determinada, la cual se puede visualizar entrando en esa pagina.
El problema vino al incluirle un sistema de comentarios (include comments_ram.php), el cual en firefox lo veo perfecto, y no solo yo, otras personas tambien, pero en otros navegadores no se ve el sistema de comentarios.

Este es el archivo comments.ram.php q incluyo en el codigo anterior, tal cual estaba y sin modificaciones:

Código PHP:
<?php
function open_file($id)
{
    if(!
file_exists('comments'))
       
mkdir('comments');
    
$file 'comments/'.$id.'.txt';
    
$fp = @fopen($file'r');
    if(!
$fp)
    {
        
$fp fopen($file'w');
        
fclose($fp);
        
$fp fopen($file'r');
    }
    return 
$fp;
}
    
    
// function to shorten long url
function shorten_long_words($str)
{
    
$maxwordlen     30;
    
$replacement    '........';
    
    
$rpls           round(strlen($replacement)/2);
    
$words          explode(' '$str);
    
    for(
$i=0$i<count($words); $i++)
    {
        
$wordlen strlen($words[$i]);
        
        if( 
$wordlen $maxwordlen)
        {
            
$del        round(($wordlen $maxwordlen)/2);
            
$mid        round($wordlen/2);
            
$start      $mid $del $rpls;
            
$end        $mid $del $rpls;

            
$first      substr($words[$i], 0$start);
            
$last       substr($words[$i], $end);
            
            
$words[$i]  = $first.$replacement.$last;
        }        
    }
    
$str implode(' '$words);
    return 
$str;
}
    
// stri_replace() function
// Avaliable in PHP 5 but defined as custom function for php 4 as stri_rep

function stri_replace($find,$replace,$string)
{
    if(!
is_array($find))
        
$find = array($find);
        
    if(!
is_array($replace))
    {
        if(!
is_array($find))
            
$replace = array($replace);
        else
        {
            
// this will duplicate the string into an array the size of $find
            
$c count($find);
            
$rString $replace;
            unset(
$replace);
            for (
$i 0$i $c$i++)
            {
                
$replace[$i] = $rString;
            }
        }
    }
    foreach(
$find as $fKey => $fItem)
    {
        
$between explode(strtolower($fItem),strtolower($string));
        
$pos 0;
        foreach(
$between as $bKey => $bItem)
        {
               
$between[$bKey] = substr($string,$pos,strlen($bItem));
               
$pos += strlen($bItem) + strlen($fItem);
        }
        
$string implode($replace[$fKey],$between);
    }
    return(
$string);
}
    
    
// VIEW COMMENTS +++++++++++++++++
function view_comments($id)
{
?>
<script type="text/javascript" language="JavaScript" src="comments_ram.js"><!--//--></script>
<div id="comments">
<script type="text/javascript" language="JavaScript">
<!--
write_comments_control(<?php echo $id ?>);
//-->
</script>
<?php
    $fp 
open_file($id);
    
$read     fread($fp80000);
    
    if(!empty(
$read))
    {
        
$post    split ('---'$read);
        for(
$i=0$i<count($post); $i++)
        {
            
$data split ('#'$post[$i]);
            
$date     $data[0];
            
$name    $data[1];
            
$email    $data[2];
            
$comment$data[3];
            
            if(!empty(
$email))
                
$name '<a href="mailto:'.$email.'">'.$name.'</a>';
?>
<div class="item">
<div class= "name">[ 2006-12-05 ] :: <?php echo $name?></div>
<div class="comment"><?php echo $comment?></div>
</div>
<?php
        
}
    }
    else
    {
        echo 
'<div class="item">No comments posted here.</div>';
    }
?>
</div>
<?php
}
    
// POST COMMENTS +++++++++++++++++    
function post_items($id)
{
    
    
// Settings::::::::::::
    
$allowed         10;                        // Number of entries to store
    
$spliter         '---';                    // String that is used to split each posts from file
    
$date            date('Y-m-d'time());    // Todays data format
    
$filter_file     'bad_words.txt';    // File that stores all words to filter
    
$replacement     '***';                        // The text that will replace bad words if found
    
    
$name         $_POST[name];
    
$email         $_POST[email];
    
$comment     $_POST[comment];    
    
    if(empty(
$name) or empty($comment))
    {
        echo 
'Name and comment can\'t be left blank';
        exit();
    }
        


// This part filters the user input ===========================================================================
    
    // Part 1: ###### Filters url injection
    
    // array of text to ban
    
$ban = Array('http://''www\.''\.com''\.net''\.org''\.edu''\.tk''\.nfo''\.uk''\.au''\.us');
    
    for(
$i=0$i<count($ban); $i++)
    {
        
$name      eregi_replace($ban[$i], ''$name);
        
$comment eregi_replace($ban[$i], ''$comment);
    }
        
    
// Part 2: ###### Filters special charecters and html tag escape situtation
    // Filter name
    
$name            ereg_replace('[^A-Za-z ]'''$name);
    
    
// Filter comment
    
$comment        ereg_replace('[#]'''$comment);
    
$comment        eregi_replace($spliter''$comment);
    
$comment         strip_tags($comment);
    
$comment         addslashes($comment);
    
    
    
//Filter email if available
    
if(!empty($email))
    {
        
$email    ereg_replace('[^A-Za-z@._]'''$email);
    }
        
    
// Part 3: ###### Seeks and filter junk long words
    
$comment shorten_long_words($comment);
        
    
// Part 4: ###### Seeks and filter bad words
    
    // The file that contains all the bad words to filter
    // Put the bad words in this file, separate words with new line
    
    
    // This reads the file contents and stores the result words in a array
    
$bad_words file($filter_file);
    
    
// Now loops through each bad words and replace every time badword found
        // Explodes each bad words in array and store it in a temporary vaiable 
        // And Makes case insensitive replacement of bad word with replacement
    // Filtering name and comment    
    
for($i=0$i<sizeof($bad_words); $i++) 
    {
        
$temp       rtrim($bad_words[$i]);
        
$name        stri_replace ($temp$replacement$name);
        
$email        stri_replace ($temp$replacement$email);
        
$comment    stri_replace ($temp$replacement$comment);
    }
        
    
// Note: I didn't filter email address
    
// End of filtering user input =====================================================================================
    
    // Now formatting out the new entry        
    
$new_post $date.'#'.$name.'#'.$email.'#'.$comment.'
'
;
    
    
//opens the file in read mood
    
$file 'comments/'.$id.'.txt';
    
$fp = @fopen($file'r');

    
// If file can be openned then do this
    
if($fp)
    {
        
//read file
        
$read     fread($fp80000);
        
        
// if not blank file then splits to find each posts
        
if(!empty($read))
        {
            
// Finds out how many time spliter found. this value+1 is the number of post stored in file
            
$count substr_count($read,$spliter);
            
$count++;    // This is number that how many post are in the file.
            
            // Start activities to delete last entry when allowed limit touches
            
if($count == $allowed)
            {
                
// Finds out the last occurance positon of spliter.
                // Required to delete the last entry if it exceeds maximum allowed limit
                
$pos strrpos($read$spliter);
                
// Now we shall delete the  string after $pos
                
$read substr($read0$pos);
            }
            
// The output to write on file
            
$output $new_post.$spliter.'
'
.$read;
        }
        else    
// When blank file then only write the new entry in file;
        
{
            
$output $new_post;
        }
            
        
//close file;
        
fclose($fp);
    }
    
    
// Now opens the file in write mood to save new item
    
$file 'comments/'.$id.'.txt';
    
$fp     fopen($file'w');                        
    
fwrite($fp$output80000);
    
fclose($fp);
}
    
// End of Functions ------------------------------------------------------------------------------------------------


$action $_POST['action'];


if(
$action == 'post')
{
    
$id $_POST['id'];
    
post_items($id);
    echo 
'<title>Adding your comment...</title><body onload="window.close();"></body>';        
}
?>