Jump to content

Recommended Posts

Here is the original code.

If you can change it to remove name_input and replace it with the session userName

 

<html>
<head>
<font face="Fixedsys">
<center>
<img src = "Banner.bmp"><br>
<title>_REMOVED_</title>
<h3><a href = "index.php">Home</a> | <b>Chat</b> | <a href="uploader.php">Upload Files</a> | <a href="staff.php">Staff</a></h3>
</font>
</head>
<body>
<font face="Comic Sans MS" font size = "2">
<hr>
<p>
Info on 'Chat':<br>
'Chat' has an 8 chats history, you can chose your own name.<br>
If you want to request a full history, please email me.<br>
<br>
<?php
/* ########################## INFO ##########################

                       Advanced shoutbox
                          Version 1.0

         Free script from WB - Webdesign for beginners.
          Visit http://plohni.com/wb for more scripts.
               Feel free to modify this script.
                              lgp

/* ########################## INFO ########################## */
/* ###################### INSTALLATION ###################### */

   // a) Adjust the configuration variables to your needs

         $file = "shouts.txt"; // Name of the file which
                               // contains the shouts
         $shouts = 8; // Number of shouts to be displayed
         $maxlength_name = "8"; // Maximum length of name
         $maxlength_text = "150"; // Maximum length of text
         $break_name = "15"; // Break name after characters
                             // without space
         $break_text = "15"; // Break text after characters
                             // without space

   // b) Copy this code to your PHP file
   // c) Copy your PHP file and the shouts file defined in
   //    variable $file to your server using ASCII mode
   // d) Make the shouts file writable (Windows: adjust
   //    security, Unix: chmod 777)

/* ###################### INSTALLATION ###################### */
/* ############# SCRIPT (EDIT AT YOUR OWN RISK) ############# */
?>
<p>
  <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
    <input type="text" value="Your name" name="input_name" maxlength="<?php echo $maxlength_name; ?>" onfocus="if(this.value=='Your name'){this.value='';}" onblur="if(this.value==''){this.value='Your name';}" /><br />
    <input type="text" value="Your text" name="input_text" maxlength="<?php echo $maxlength_text; ?>" onfocus="if(this.value=='Your text'){this.value='';}" onblur="if(this.value==''){this.value='Your text';}" /><br />
    <input type="submit" value="Shout!" />
  </form>
</p>
<hr />
<p>
<?php
  //function to break text after x characters
  function str_break($str,$maxlen){
    $nobr = 0;
    $len = strlen($str);

    for($i=0;$i<$len;$i++){
      if(($str[$i]!=' ') && ($str[$i]!='-') && ($str[$i]!="\n")){
        $nobr++;
      }else{
        $nobr = 0;

        if($maxlen+$i>$len){
          $str_br .= substr($str,$i);
          break;
        }
      }
      
      if($nobr>$maxlen){
        $str_br .= ' '.$str[$i];
        $nobr = 1;
      }else{
        $str_br .= $str[$i];
      }
    }
    
    return $str_br;
  }

  //number of shouts to be displayed
  $display = (isset($_GET["show"]) ? "all" : $shouts);
?>
</p><p>
<?php
  //insert new shout
  $input_name = $_POST["input_name"];
  $input_text = $_POST["input_text"];
  
  //check if form has been submitted
  if(isset($input_name) && isset($input_text) && $input_name!="Your name" && $input_text!="Your text" && strlen($input_name)>0 && strlen($input_text)>0){
    //get last name and comment
    $handle = fopen($file,"r");

    while(!feof($handle)){
      $row = fgets($handle,999999);
      list($tmp_name,$tmp_text) = split("\|\|\|\|\|",$row);

      if($tmp_name != "" && $tmp_text != ""){
        $last_name = $tmp_name;
        $last_text = str_replace("\n","",$tmp_text);
      }
    }
    
    fclose($handle);

    $input_name = str_break($input_name,$break_name); //break name
    $input_name = str_replace("<","<",$input_name); //prevent html input
    $input_name = str_replace(">",">",$input_name); //prevent html input
    $input_name = stripslashes($input_name); //strip slashes
    
    $input_text = str_break($input_text,$break_text); //break text
    $input_text = str_replace("<","<",$input_text); //prevent html input
    $input_text = str_replace(">",">",$input_text); //prevent html input
    $input_text = stripslashes($input_text); //strip slashes

    if($last_name != $input_name || $last_text != $input_text){
      $handle = fopen($file,"a"); //open shouts file to write (append)
      fputs($handle,"$input_name|||||$input_text\n"); //insert name and shout
      fclose($handle); //close file handle
    }
  }

  //read shouts file
  $names = array(); //array to store names
  $shouts = array(); //array to store shouts
  $handle = fopen($file,"r"); //open shouts file to read
  
  while(!feof($handle)){ //read row by row
    $row = fgets($handle,999999);
    list($name,$shout) = split("\|\|\|\|\|",$row);
    
    if($name){
      array_push($names,$name);
      array_push($shouts,$shout);
    }
  }
  
  fclose($handle); //close file handle

  //reverse arrays so that new lines are first
  $names = array_reverse($names);
  $shouts = array_reverse($shouts);

  //number of shouts to really print
  $max = ($display == "all" ? count($names) : $display);

  //print shouts
  for($i=0;$i<$max && $i<count($names);$i++){
    ?><strong><?php echo $names[$i]; ?>:&nbsp</strong><?php echo $shouts[$i]; ?><br>
  <?php } ?>
</p>
<hr>
</p>
</font>
</body>
<footer>
<font face = "Times New Roman" font size = 1>
Copyright© 2009, Caleb Blankemeyer<br>
</center>
</html>

 

Okay, I'm going to fix this for you, but a few things.

 

...BEGIN SOAPBOX

 

1.  You do not own scripts you have not paid for and did not develop yourself.  Don't put a copyright on it.  You haven't earned that right.  Someone is letting you use that code freely, but THEY own that code.  Give credit where credit is due. 

 

2.  Learn the language if you're going to ask for help.  If you aren't doing the basic work in trying to understand something, you shouldn't ask for someone to do it for you without compensation.  We couldn't ask you basic questions about your code.  It's one thing to not know the ins and outs of a language when its something you write, because you still know what its trying to do.  It's another thing to grab something without knowing what it does, muck with it, and then ask for help without doing your part.

 

...END SOAPBOX

 

You'll want to put back your common.php and get user name methods.

 

<?php

   //function to break text after x characters
   function str_break($str,$maxlen){
     $nobr = 0;
     $len = strlen($str);

     for($i=0;$i<$len;$i++){
       if(($str[$i]!=' ') && ($str[$i]!='-') && ($str[$i]!="\n"))
       {
         $nobr++;
       }
       else
       {
         $nobr = 0;

         if($maxlen+$i>$len)
         {
           $str_br .= substr($str,$i);
           break;
         }
       }

      if($nobr>$maxlen)
      {
        $str_br .= ' '.$str[$i];
        $nobr = 1;
      }
      else
      {
        $str_br .= $str[$i];
      }
    }
    return $str_br;
  }

   $file = "shouts.txt";
   $shouts = 8; // Number of shouts to be displayed
   $maxlength_text = "140"; // Maximum length of text
   $break_name = "15"; // Break name after characters without space
   $break_text = "15"; // Break text after characters without space

   // b) Copy this code to your PHP file
   // c) Copy your PHP file and the shouts file defined in
   //    variable $file to your server using ASCII mode
   // d) Make the shouts file writable (Windows: adjust
   //    security, Unix: chmod 777)

  $input_name = $_SESSION['usersname'];

  //number of shouts to be displayed
  $input_text = '';
  if( isset( $_POST['input_text']) && strlen( $_POST['input_text']))
  {
    $input_text = $_POST['input_text'];
    //get last name and comment
    $handle = fopen($file,"r");

    if( $handle)
    {
      while(!feof($handle))
      {
        $row = fgets($handle,999999);
        if( $row)
        {
          list($tmp_name,$tmp_text) = split("\|\|\|\|\|",$row);
  
          if($tmp_name != "" && $tmp_text != "")
          {
            $last_name = $tmp_name;
            $last_text = str_replace("\n","",$tmp_text);
          }
        }
      }
    }
    
    fclose($handle);
    
    $input_text = str_break($input_text,$break_text); //break text
    $input_text = str_replace("<","<",$input_text); //prevent html input
    $input_text = str_replace(">",">",$input_text); //prevent html input
    $input_text = stripslashes($input_text); //strip slashes

    if($last_text != $input_text){
      $handle = fopen($file,"a"); //open shouts file to write (append)
      fputs($handle,"$input_name|||||$input_text\n"); //insert name and shout
      fclose($handle); //close file handle
    }
  }

  $display = (isset($_GET["show"]) ? "all" : $shouts);

  //read shouts file
  $names = array(); //array to store names
  $shouts = array(); //array to store shouts
  $handle = fopen($file,"r"); //open shouts file to read
  
  if( $handle)
  {  
    while(!feof($handle)){ //read row by row
      if( $row = fgets($handle,999999)){
        list($name,$shout) = split("\|\|\|\|\|",$row);
        if($name){
          array_push($names,$name);
          array_push($shouts,$shout);
        }
      }
    }
  }

  fclose($handle); //close file handle

  //reverse arrays so that new lines are first
  $names = array_reverse($names);
  $shouts = array_reverse($shouts);

  //number of shouts to really print
  $max = ($display == "all" ? count($names) : $display);
?>
<html>
<head>
<font face="Fixedsys">
<center>
<img src = "Banner.bmp"><br>
<title>_REMOVED_</title>
<h3><a href = "index.php">Home</a> | <b>Chat</b> | <a href="_REMOVED_">_REMOVED_</a> | <a href="staff.php">Staff</a></h3>
</font>
</head>
<body>
<font face="Comic Sans MS" font size = "2">
<hr>
<p>
Info on 'Chat':<br>
'Chat' has an 8 chats history, max length of 140 characters.<br>
If you want to request a full history, please email me.<br>
<br>
<p>
  <?php
    echo '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
    echo '<b>'.$_SESSION['userName'].'</b><br />';

    echo '<input type="text" value="Your Text" name="input_text" maxlength="'.$maxlength_text.'"'
         .' onfocus="if(this.value==\'Your text\'){this.value=\'\';}"'
         .' onblur="if(this.value==\'\'){this.value=\'Your text\';}" /><br />';
  ?>
  <input type="submit" value="Shout!" />
  </form>
</p>
<hr />
<p>
<?php
  //print shouts
  for($i=0;$i<$max && $i<count($names);$i++)
  {
    echo '<strong> '.$names[$i].':&nbsp</strong>'.$shouts[$i].'<br>';
  } 
?>
</p>
<hr>
</p>
</font>
</body>
<footer>
<font face = "Times New Roman" font size = 1>
Copyright) 2009, _REMOVED_<br>
</center>
</html>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.