PHP Classes
Icontem

File: chatbox.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Keizer  >  Shared Memory  >  chatbox.php  
File: chatbox.php
Role: Example script
Content type: text/plain
Description: Usage example
Class: Shared Memory
Store and retrieve information in shared memory
 

Contents

Class file image Download
<?
    
include_once "sharedmemory.class.php";

    
$s = new SharedMemory(54645645);                    //create instance of shared memory object
    
$history $s->Get();                        //read contents
    
    
$username = isset($_POST["username"])?$_POST["username"]:"Anonymous";
    
    
//add user message to history and write result back to shared memory
    
if (isset($_POST["chat"]) && $_POST["chat"] != "") {
        
$history .= sprintf("%s says: %s"$username$_POST["chat"].chr(13));
        
//strip oldest message if history exceeds 200 lines
        
if (substr_count($historychr(13)) > 200) {
            
$history substr($history1+strpos($historychr(13)));
        }
        
$s->Set($history);
    }
    
    
//render history to textarea
    
echo "<textarea rows=30 cols=80>$history</textarea>";
    
    
//render user input controls
    
echo "<form method='POST'>";
    echo 
"  <input type='text' size=20 name='username' value='$username'>";
    echo 
"  <input type='text' size=40 name='chat'>";
    echo 
"  <input type='submit' value='Send/Refresh'>";
    echo 
"</form>";
?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products