IP BASED PASSWORD                                                           as3,php


    This tutorial is very similar to hit counter tutorial so for more details on actionscript please go check that out. The difference between these two is minimal, and i explaing those in here. At the end we should get something like this :

     Create new actionscript 3.0 flash file. Create two dynamic text fields. Set their instance names to output1_txt and status_txt. Now open actions (press F9) and enter following actionscript.


stop();
var urlLoader:URLLoader = new URLLoader( );
 
urlLoader.addEventListener(IOErrorEvent.IO_ERROR, handleIOError );
urlLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, handleHttpStatus );
urlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,handleSecurityError);
urlLoader.addEventListener(Event.COMPLETE, handleComplete );
 
urlLoader.dataFormat = URLLoaderDataFormat.VARIABLES; 
 
urlLoader.load( new URLRequest("ipData.txt"));
 
function handleIOError( event:IOErrorEvent ):void
{
    trace( "IO error: " + event.text );
}
function handleHttpStatus( event:HTTPStatusEvent ):void
{
    trace( "HTTP Status = " + event.status );
}
function handleSecurityError( event:SecurityErrorEvent ):void
{
    trace( "Security Error: " + event.text );
}
function handleComplete( event:Event ):void

{
    trace( "Data loaded" );
    trace( "IP :: " + urlLoader.data.ip );
	output1_txt.text = urlLoader.data.ip;
	
	if(urlLoader.data.ip == "100.100.00.100"){
		gotoAndStop(2);
	}else{
		status_txt.text="Your IP does not match. Access denied."
	}
}



     As I said the majority of scripts is identical with hit counter project. Difference is at 32-36. This if condition checks if loaded variable containing visitors IP address matches the tring to the right of it. The "100.100.00.100" string should be your IP. If those two matches, script will move to frame 2 (or whatever else you want him to do). If that is not the case, displays error message. The last what we need is php code. Again the idea is same, all we added was code to get visitors IP address (lines 2-17).




DOWNLOAD SOURCE FILE