Location: PHPKode > projects > Remote Mail > index.php
<?php
	


	/*
	 *
	 *	Remote Mail Client
	 *	CopyLEFT 2004 by Maurizio Pinotti
	 *
	 *	You can freely distribute this script as long as you do *NOT* edit it:
	 *	editing is only permitted for private use.
	 *
	 *	----------------------------------------------------------------------
	 * 	 Official site: http://www.pinottinet.com/rmail
	 *	----------------------------------------------------------------------
	 *
	 */



	// ------------------------- [ NO USER CONFIGURABLE ELEMENTS BELOW HERE ] ------------------------	

	// alternate login
	setcookie("rmail_user", "");
	setcookie("rmail_pwd", "");
	

	// get the action taken, no validation is required for this string
	$p_action = $_GET['act'];
	
	// load static configuration 
	require_once ("config.php");
	$CSS_STYLE = $DEFAULT_STYLE;
	
	// define common dynamic links
	$self_link = $_SERVER['PHP_SELF'];
	
	// try to guess user's language
	$lang_file = $LANG_DIR . substr ($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) . ".php";
	if ( !file_exists ($lang_file) ) $lang_file = $DEFAULT_LANG_FILE;
	require_once ($lang_file);

	if ($p_action == "" || $p_action == "success") {
	
										// -- DISPLAY LOGIN/REGISTER WINDOW AND EVENTUALLY A CONFIRMATION MESSAGE --

		$main_page_link = $MAIN_PAGE;
		$register_link = "{$_SERVER['PHP_SELF']}?act=register";
		$title = "{$PROGRAM_NAME} v{$PROGRAM_VERSION} by Maurizio Pinotti";
		if ($p_action == "success") $alert_message = $lang['registration_successful'];
		$data = $lang['welcome'];
		
		require_once ("skin/skin_login.php");
	}
	
	else if ($p_action == "register") { 
	
										// -- DISPLAY REGISTER WINDOW --
	
		// which error(s) occurred?
		$p_errors = $_GET['errors'];
		
		// get eventual old values for the user and email fields
		$p_user = $_GET['user'];
		$p_email = $_GET['email'];
	
		// set one option for each language file
		require_once ("lib/lib_misc.php");
		$form_options = get_files_list ($LANG_DIR, $lang_file);
	 
	 	// define title and other links
	 	$title = "{$PROGRAM_NAME} v{$PROGRAM_VERSION} by Maurizio Pinotti";
		$form_action = "{$_SERVER['PHP_SELF']}?act=doreg";

		// check if we are returning here after some errors
		if ($p_errors) { 
		
			// process each error
			$error = "{$lang['errors']}";
			foreach ( explode (".", $p_errors) as $errno ) { 
				if ($errno) {
					switch ( $errno ) { 
						case 0 /* passwords don't match */ : { $data .= $lang['pass_no_match'] . "<br>"; break; }
						case 1 /* invalid user */ : { $data .= $lang['invalid_user'] . "<br>"; break; }
						case 2 /* invalid pass */ : { $data .= $lang['invalid_pass'] . "<br>"; break; }
						case 3 /* user exists */ : { $data .= $lang['user_exists'] . "<br>"; break; }
						case 4 /* incorrect mail */ : { $data .= $lang['incorrect_mail'] . "<br>"; break; }
					} // esac
				} // fi
			} // hcaerof
		}
		else { 
		
			// no errors
			$data = $lang['register_help'];
		}
		
		$field_user = urldecode ($p_user);
		$field_email = urldecode ($p_email);
		
		require_once ("skin/skin_register.php");
	}
	
	else if ($p_action == "doreg") { 
	
										// -- SAVE REGISTRATION INFORMATION --
										
		// parse parameters
		$p_user = $_POST['field_user'];
		$p_pass = $_POST['field_pass'];
		$p_pass2 = $_POST['field_pass2'];
		$p_lang = $_POST['field_lang'];
		$p_email = $_POST['field_email'];
	
		// open db
		$CONNECTION = mysql_connect ($DB_ADDRESS, $DB_USER, $DB_PASS);
		$DATABASE = mysql_select_db ($DB_NAME, $CONNECTION);

		// parameters validation
		$errors = "";
		if ($p_pass !== $p_pass2) $errors .= ".0";																	// passwords don't match
		if ( !$p_user || strlen ($p_user) > 20 || ereg ('[^A-Za-z0-9_@]', $p_user) ) $errors .= ".1";				// invalid user
		if ( !$p_pass || strlen ($p_pass) > 20 || ereg ('[^A-Za-z0-9]', $p_pass) ) $errors .= ".2";				// invalid pass
		$result = mysql_fetch_row ( mysql_query ("SELECT * FROM rmail_logins WHERE ruser='{$p_user}'") );
		if ( $result ) $errors .= ".3";																				// user already exists
		//echo ("CHECK 1: " . preg_match ("/.\@.\.{2,3}?(\.{2,3})/", $p_email));
		// use regular expression: "at least one char", '@', "at least one char", '.', "at least one char"
		if ($p_email && ( strlen ($p_email) > 40 || !preg_match ("/.{1,}\@.{1,}\..{1,}/", $p_email) )) $errors .= ".4";		// invalid email
	
		if (!$errors) {
		
			// ensure that login table exists
			$sql = "CREATE TABLE IF NOT EXISTS `rmail_logins` ("
			."  `ruser` varchar(20) NOT NULL default '',"
			."  `rpass` varchar(20) NOT NULL default '',"
			."  `rlang` char(2) default NULL,"
			."  `remail` varchar(40) default NULL,"
		 	."  `last_access` datetime default NULL,"
		 	."  `opt_order_accounts` int(11) default '1',"
			."  `opt_log_messages` int(11) default '0',"
			."  `opt_hide_passwords` int(11) default '1',"
			."  `opt_hide_empty_accounts` int(11) default '0',"
			."  `opt_skin` varchar(20) default NULL,"
			."  `reload` int(11) default '0',"
			."  PRIMARY KEY  (`ruser`)"
			.") TYPE=MyISAM";
			$result = mysql_query ($sql);
			
			// add the user and go back to login page
			$sql = "INSERT INTO rmail_logins ( ruser , rpass , rlang , remail , last_access ) ";
			$sql .= "VALUES ( '{$p_user}', '{$p_pass}', '{$p_lang}', '{$p_email}', 'NULL' );";
			$result = mysql_query ($sql);
			$browser_redir = "{$_SERVER['PHP_SELF']}?act=success";
		}
		else { 
		
			// go back to register page
			$enc_user = urlencode ($p_user);
			$enc_email = urlencode ($p_email);
			$browser_redir = "{$_SERVER['PHP_SELF']}?act=register&errors={$errors}&user={$enc_user}&email={$enc_email}";
		}
		
		// close db and set page title
		mysql_close ($CONNECTION);
		$title = "{$lang['operation_complete']} @ {$PROGRAM_NAME}";
		
		require ("skin/skin_op_done.php");
	}

?>
Return current item: Remote Mail