Results 1 to 1 of 1
  1. #1
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default Flat file, Javascript Alert Online Users Thingy?

    Here you go, Thought id create it as I was bored... could be drastically changed.

    index.php
    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <
    html>

    <
    head>
        <
    meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
        <
    meta name="author" content="James Rozee">

        <
    title>Javascript AJAX Alert Thingy</title>
    </
    head>
    <
    script type="text/javascript">
    function 
    checkAlerts ()
    {
        if ( 
    window.XMLHttpRequest )
        {
            
    Ajax = new XMLHttpRequest ();
        }
        else if ( 
    window.ActiveXObject )
        {
           
    Ajax = new ActiveXObject"Microsoft.XMLHTTP" );
        }
        
    Ajax.open"POST""alertCheck.php"true );
        
    Ajax.onreadystatechange alertUsers;
        
    Ajax.setRequestHeader"Content-Type""application/x-www-form-urlencoded" );
        
    Ajax.send"null" );
    }
    function 
    alertUsers ()
    {
        if ( 
    Ajax.readyState == )
        {
            if ( 
    Ajax.status == 200 )
            {
                if ( 
    Ajax.responseText == "Error" )
                {
                    
    // Repeat check, this is probably bad practice...?
                    
    checkAlerts ();
                }
                else
                {
                    
    alert Ajax.responseText );
                    
    checkAlerts ();
                }
            }
        }
    }

    </
    script>

    <
    body onLoad="checkAlerts()">

    </
    body>
    </
    html
    alertCheck.php
    PHP Code:
    <?php
    session_start 
    ();
    /**
     * @copyright 2008 - James Rozee - DisasterPiece
     * @about hmm, alert users
     */

    require_once ( 'alertFunctions.php' );

    $alert grabAlerts ();
    if( 
    $alert == 'Error' )
    {
        echo ( 
    'Error' );
    }
    else
    {
        if ( 
    $parts explode'.@~hash'$alert ) )
        {
            if ( 
    $parts] - date("dmogi") >= )
            {
                if( 
    $_SESSION'alertCheck' ] == $parts] )
                {
                    echo ( 
    'Error' );
                }
                else
                {
                    
    $_SESSION'alertCheck' ] = $parts];
                    echo ( 
    $parts] );
                }
            }
            else
            {
                echo ( 
    'Error' );    
            }
        }
        else
        {
            echo ( 
    'Error' );
        }
    }
    ?>
    alertFunctions.php
    PHP Code:
    <?php

    /**
     * @copyright 2008 - James Rozee - DisasterPiece
     * @about hmm, alert users
     */


    function alertUsers $message )
    {
        
    $fileAlerts 'alerts.txt';
        if ( 
    $message == '' )
        {
            return 
    'You can\'t send a blank message to users, thats just stupid...';
        }
        elseif ( 
    $message != '' )
        {
            
    $fileHandle fopen $fileAlerts'w' ) or die ( 'Sorry, failed to open that file.' );
            if ( ! 
    fwrite $fileHandle$message '.@~hash' date("dmogi") ) )
            {
                return 
    'Failed to write to file...';    
            }
            else
            {
                return 
    'Current users should receive the alert in the next 60 seconds...';
            }
        }
    }

    function 
    grabAlerts ()
    {
        
    $fileAlerts 'alerts.txt';
        if ( ! 
    $fileHandle fopen $fileAlerts'r' ) )
        {
            return 
    'Error';
        }
        else
        {
            if ( ! 
    $stringAlert fread $fileHandlefilesize $fileAlerts ) ) )
            {
                return 
    'Error';
            }
            else
            {
                return 
    $stringAlert;
            }
        }
    }


    ?>
    alertSubmit.php
    PHP Code:
    <?php

    /**
     * @copyright 2008 - James Rozee - DisasterPiece
     * @about hmm, alert users
     */

    require_once ( 'alertFunctions.php' );

    if ( 
    $_GET'message' ] == '' )
    {
        
    }
    elseif ( 
    $_GET'message' ] != '' )
    {
        echo ( 
    alertUsersstrip_tags $_GET'message' ] ) ) );
    }
    ?>
    You will need to create a text file "alerts.txt", inside DIR of the files that start with "alert"

    You cannot send the same alert twice in a consecutive period.
    To send an alert, you will need to go alertSubmit.php?message=message here
    Use method GET on a form, manually do it or change it to POST and post it via form.

    Download all the files at once? - (*.zip) - Click here

    Also, I know I didn't leave my cPanel information on this script

    try it, http://www.jamesrozee.com/alertUsers/index.php - Stay on that page whilst you send an alert via this page http://www.jamesrozee.com/alertUsers...echangemexlala
    Last edited by Protege; 27-05-2008 at 07:52 PM.
    Hi, names James. I am a web developer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •