Sajax v0.12 - You are a guinea pig - This example illustrates the simplest possible graffiti wall ( last 10 messages ). It isn't meant to be perfect, featureful, or even useful.
Loading..

Example Source :
<?php
    
//
    // The world's least efficient wall implementation
    //
    
require("Sajax.php");
    function 
colorify_ip($ip)
    {
        
$parts explode("."$ip);
        
$color sprintf("%02s"dechex($parts[1])) .
                 
sprintf("%02s"dechex($parts[2])) .
                 
sprintf("%02s"dechex($parts[3]));
        return 
$color;
    }
    
    function 
add_line($msg) {
        
$f fopen("wall.html""a");
        
$dt date("Y-m-d h:i:s");
        
$msg strip_tags(stripslashes($msg));
        
$remote $_SERVER["REMOTE_ADDR"];
        
// generate unique-ish color for IP
        
$color colorify_ip($remote);
        
fwrite($f"<span style=\"color:#$color\">$dt</span> $msg<br>\n");
        
fclose($f);
    }
    
    function 
refresh() {
        
$lines file("wall.html");
        
// return the last 25 lines
        
return join("\n"array_slice($lines, -10));
    }
    
    
$sajax_request_type "GET";
    
sajax_init();
    
sajax_export("add_line""refresh");
    
sajax_handle_client_request();    
?>
<html>
<head>
    <title>Wall</title>
    <style>
    .date { 
        color: blue;
    }
    </style>
    <script>
    <?
    sajax_show_javascript
();
    
?>
    
    var check_n = 0;
    var old_data = "--";
    
    function refresh_cb(new_data) {    
        if (new_data != old_data) {
            document.getElementById("wall").innerHTML = new_data;
            setTimeout("refresh()", 1000);
            old_data = new_data;
        } else {
            setTimeout("refresh()", 2500);
        }
        document.getElementById("status").innerHTML = "Checked #" + check_n++;
    }
    
    function refresh() {
        document.getElementById("status").innerHTML = "Checking..";
        x_refresh(refresh_cb);
    }
    
    function add_cb() {
        // we don't care..
    }

    function add() {
        var line;
        var handle;
        handle = document.getElementById("handle").value;
        line = document.getElementById("line").value;
        if (line == "") 
            return;
        sajax_request_type = "POST";
        x_add_line("[" + handle + "] " + line, add_cb);
        document.getElementById("line").value = "";
    }
    </script>
    
</head>
<body onload="refresh();">
<div width=100% align="right">
    <?php include("ads.php"); ?>
</div>
<br/>
<form name="f" action="#" onsubmit="add();return false;">
    <b>Sajax
    v<?= $sajax_version?></b>
    -
    You are a guinea pig
    -
    This example illustrates the simplest possible graffiti wall ( last 10 messages ).
    It isn't meant to be perfect, featureful, or even useful.<br/>
    
    <input type="text" name="handle" id="handle" value="(name)"
        onfocus="this.select()" style="width:130px;">
    <input type="text" name="line" id="line" value="(enter your message here)"
        onfocus="this.select()"
        style="width:300px;">
    <input type="button" name="check" value="Post message"
        onclick="add(); return false;">
    <div id="wall"></div>
    <div id="status"><em>Loading..</em></div>
</form>
</body>
</html>
<hr>
    <B>Example Source :</B>
<hr>
<table border=0 width=100%>
<tr>
    <td width=70%>
        <?php show_source(__FILE__?>    
    </td>
    <td width=20% valign="top" align="right">
        <?php include("adsv.php"); ?>
    </td>
</tr>
</table>