PDA

View Full Version : Flat file, Javascript Alert Online Users Thingy?



Protege
27-05-2008, 07:46 PM
Here you go, Thought id create it as I was bored... could be drastically changed.

index.php


<!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 == 4 )
{
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
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[ 1 ] - date("dmogi") >= 0 )
{
if( $_SESSION[ 'alertCheck' ] == $parts[ 0 ] )
{
echo ( 'Error' );
}
else
{
$_SESSION[ 'alertCheck' ] = $parts[ 0 ];
echo ( $parts[ 0 ] );
}
}
else
{
echo ( 'Error' );
}
}
else
{
echo ( 'Error' );
}
}
?>alertFunctions.php

<?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 ( $fileHandle, filesize ( $fileAlerts ) ) )
{
return 'Error';
}
else
{
return $stringAlert;
}
}
}


?>alertSubmit.php

<?php

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

require_once ( 'alertFunctions.php' );

if ( $_GET[ 'message' ] == '' )
{

}
elseif ( $_GET[ 'message' ] != '' )
{
echo ( alertUsers( strip_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 (http://www.jamesrozee.com/alertUsers/alertUsers.zip)

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/alertSubmit.php?message=alertherechangemexlala

Want to hide these adverts? Register an account for free!