Location: PHPKode > scripts > CosmicBannerRotator > bannerrotator/admin.php
<?

##-----------------------------------------------------------------##
##                                                                 ##
##                                                                 ##
## © Copyright Stephen Heylings 2003. All rights reserved. No part ##
## of this or any of the attached documents shall be               ##
## reproduced/stored in any way whatsoever without written         ##
## permission from the Copyright holder.                           ##
##   The Copyright holder holds no responsibility for errors or    ##
## omissions. No liability is assumed in any way for damages       ##
## resulting from the use of this document/program.                ##
##                                                                 ##
## Have a nice day.                                                ##
##                                                                 ##
##                                                                 ##
##-----------------------------------------------------------------##


#include functions
include ('printform.inc.php');

#determine users request
if(isset($_POST['method']))
{
	switch($_POST['method'])
	{
		case "login":
			if(checkpass()==true)
			{
				admin();
			}
			else
			{
				printlogin("Incorrect password, please try again");
			}
		break;
		
		case "update";
			update();
		break;
		
		default:
			print login();
	}
}
else
{
	printlogin();
}

function printlogin($message="")
{
print <<<EndHTML

	<html>
	<form name=login method=post action=admin.php>
	
	<div align=center><font face='Verdana, Arial, Helvetica, sans-serif' color='#336699' size=5>Admin Log-in</font></div>
	<br>
	<div align=center><font face='Verdana, Arial, Helvetica, sans-serif' color='#993333' size=3>$message</font></div>	
	<br>
	<table cellSpacing='0' cellPadding='0' width='250' bgColor='#336699' border='0' align='center'><tr><td>
	<table border='0' cellSpacing='1' cellPadding='4' width='250' align='center'>
	<tr bgColor='#abd1fc'>
		<td><font face='Verdana, Arial, Helvetica, sans-serif' size=2>Username:</font></td>
		<td><input type=text name=user /></td>
	</tr>
	
	<tr bgColor='#abd1fc'>
		<td><font face='Verdana, Arial, Helvetica, sans-serif' size=2>Password:</font></td>
		<td><input type=password name=pass /></td>
	</tr>
	</table>
	</table>
	<br>
	<div align=center><input type=submit value='Log In' /></div>
		<input type=hidden name=method value=login />
	</form>
	</html>

EndHTML;
	
}#endfunction

function admin($message="")
{
$olduser = $_POST['user'];
print <<<EndHTML

<html>
<form name=admin method=post action=admin.php>
<div align=right><font face='Verdana, Arial, Helvetica, sans-serif' size=2><a href="javascript:window.location='admin.php'">logout</a></font></div>
<div align=center><font face='Verdana, Arial, Helvetica, sans-serif' color='#336699' size=5>Update User</font></div>
<br>
<div align=center><font face='Verdana, Arial, Helvetica, sans-serif' color='#993333' size=3>$message</font></div>
<br>
<table cellSpacing='0' cellPadding='0' width='300' bgColor='#336699' border='0' align='center'><tr><td>
<table border='0' cellSpacing='1' cellPadding='4' width='300' align='center'>

<tr bgColor='#abd1fc'>
	<td><font face='Verdana, Arial, Helvetica, sans-serif' size=2>New Username:</font></td>
	<td><input type=text name=user /></td>
</tr>

<tr bgColor='#abd1fc'>
	<td><font face='Verdana, Arial, Helvetica, sans-serif' size=2>New Password:</font></td>
	<td><input type=password name=pass1 /></td>
</tr>
<tr bgColor='#abd1fc'>
	<td><font face='Verdana, Arial, Helvetica, sans-serif' size=2>New Password:<br><font size=1>(retype password)</font></font></td>
	<td><input type=password name=pass2 /></td>
</tr>

</table>
</table>
<br>
<div align=center><input type=submit value='Update User' /></div>
<input type=hidden name=olduser value=$olduser />
<input type=hidden name=method value=update />

</form>
</html>

EndHTML;
}

function update()
{
	$user=$_POST['user'];
	$olduser=$_POST['olduser'];
	$pass1=$_POST['pass1'];
	$pass2=$_POST['pass2'];
	
	if($pass1==$pass2)
	{
		#remove old user's file
		if (file_exists($olduser.".txt"))
		{
			unlink ($olduser.".txt");
		}

		#blank new user's file and open for write access
		if (!$handle = fopen($user.".txt", 'w+'))
		{
			#failed to open file
			exit;
		}#endif

		#Write data to file
		if (!fwrite($handle, crypt($pass1)))
		{
			#failed to write to file
			exit;
		}#endif

		#close file handle
		fclose($handle);
	
		admin("User login sucessfully updated.");
		
	}#endif
	else
	{
		#passwords dont match
		admin("Passwords do not match. Please try again.");
	}#endelse

}#endfunction

?>
Return current item: CosmicBannerRotator