Serial.php
[code]
<?php
serial::unsafe_mode();
$IN = serial::parse_incoming();
$serial = new serial();

class serial {
	private		$out			= ""; //html output

	private		$keycode		= array(); //numeriek
	private		$keycode2		= array(); //numeriek met # en *
	private		$serials		= array(); //kleine letters en cijfers
	private		$serials2		= array(); //hoofd -en kleine letters en cijfers
	private		$serials3		= array(); //hoofdletters en cijfers
	private		$serials4		= array(); //hoofdletters
	private		$serials5		= array(); //kleine letters
	private		$serials6		= array(); //hoofd -en kleine letters
	
	protected	$serialhtml		= "";
	protected	$keycodehtml	= "";

	public function __construct() { //constructor
		global $IN;
		
		//verschillende arrays opstellen
		$this->keycode  = range(0, 9);
		$this->keycode2 = array_merge(range(0, 9), array('#', '*'));
		$this->serials  = array_merge(range('a', 'z'), range(0, 9));
		$this->serials2 = array_merge(range('a', 'z'), range(0, 9), range('A', 'Z'));
		$this->serials3 = array_merge(range('A', 'Z'), range(0, 9));
		$this->serials4 = range('A', 'Z');
		$this->serials5 = range('a', 'z');
		$this->serials6 = array_merge(range('A', 'Z'), range('a', 'z'));

		$this->out = self::page();

		$IN['code'] = isset($IN['code']) ? $IN['code'] : 'default';
		switch ($IN['code']) {
			case 'serial':
				$this->genserial();
			break;

			case 'keycode':
				$this->genkeycode();
			break;
		}

		$this->output();
		exit(0);
	}

	private function genserial() {
		global $IN;
		$k = array('format', 'type', 'i', 'case', );
		foreach ($k as $K) {
			if (!isset($IN[ $K ]) || empty($IN[ $K ])) {
				return;
			}
		}

		switch (strtoupper($IN['type'])) {
			case 'C':
				$choice = 'keycode';
			break;

			case 'L':
				switch ($IN['case']) {
					case 'H':
						$choice = 'serials4';
					break;

					case 'K':
						$choice = 'serials5';
					break;

					case 'A':
					default:
						$choice = 'serials6';
					break;
				}
			break;

			case 'A':
			default:
				switch ($IN['case']) {
					case 'H':
						$choice = 'serials3';
					break;

					case 'K':
						$choice = 'serials';
					break;

					case 'A':
					default:
						$choice = 'serials2';
					break;
				}
			break;
		}
					

		if (!strstr($IN['format'], '-')) {
			$gen = array($IN['format']);
		} else {
			$gen = explode('-', $IN['format']);
		}
		
		$newgen = array();
		$randarr = $this->$choice;
		
		for ($i=0;$i<intval($IN['i']);$i++) {			//één iteratie is één generatie
			foreach ($gen as $g) {						//één iteratie is één array value
				$comp = "";								//string stuk
				for ($k=0;$k<strlen($g) - 0;$k++) {		//één iteratie is één letter
					$comp .= $randarr[ mt_rand(0, count($randarr) - 1) ];
				}
				$newgen[] = $comp;
			}
			$this->serialhtml .= implode('-', $newgen).'<br />';
			$newgen = array();
		}
	}

	private function genkeycode() {
		global $IN;

		$k = array('j','i','sharp');
		foreach ($k as $K) {
			if (!isset($IN[ $K ]) || empty($IN[ $K ])) {
				return;
			}
		}

		switch (strtoupper($IN['sharp'])) {
			case 'J':
				$choice = 'keycode2';
			break;

			case 'N':
			default:
				$choice = 'keycode';
			break;
		}

		$newgen  = array();
		$randarr = $this->$choice;

		for ($i=0;$i<intval($IN['i']);$i++) {
			$comp = "";
			for ($j=0;$j<intval($IN['j']);$j++) {
				$comp .= $randarr[ mt_rand(0, count($randarr) - 1) ];
			}
			$this->keycodehtml .= $comp.'<br />';
		}
	}

	private function output() {
		$this->out = str_replace('{OUT.KEYCODES}', $this->keycodehtml, $this->out);
		$this->out = str_replace('{OUT.SERIALS}' , $this->serialhtml , $this->out);

		$this->out = preg_replace('#\{IN.(.*?)\}#sie', '$this->getparam("IN","\1");', $this->out);
		
		$this->SendRequiredHeaders();

		echo $this->out;
		exit(0);
	}

	private function getparam($type="IN", $param='x') {
		self::safe_mode();
		return htmlentities($GLOBALS[ $type ][ strtolower($param) ], ENT_QUOTES);
		self::unsafe_mode();
	}

	private function SendRequiredHeaders() {
		$headers = array();
		$h		 = &$headers;

		$s		 = implode(' ', array_values($_SERVER));

		$h['application/xhtml+xml']		= 'Content-type: application/xhtml+xml;charset=utf-8';
		$h[]							= 'Expires: Mon, 26 Jul 1997 05:00:00 GMT';
		$h[]							= 'Last-Modified: '.gmdate("D, d M Y H:i:s").' GMT';
		$h[]							= 'Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0';
		$h[]							= 'Pragma: no-cache';

		foreach ($h as $req => $header) {
			if (!is_numeric($req) && !stristr($s, $req)) {
				continue;
			}

			header($header);
		}
	}

	public static function safe_mode() {
		error_reporting(E_PARSE);
	}

	public static function unsafe_mode() {
		error_reporting(E_ALL);
	}

	private static function page() {
		$xml = '<'.'?xml version="1.0" encoding="UTF-8" ?'.'>'; //phphulp crasht hierop
		$out = <<<EOF
{$xml}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
	<head>
		<title>
			Keycode -&#38; serialmaker
		</title>

		<script type="text/javascript">
		<!--//-->
		<![CDATA[//>
		<!--
			//vars
			var serialtype, serialcase, keycodesharp;

			function init() {
				//document.krijgElementDoorId
				serialtype		= document.getElementById("serialtype");
				serialcase		= document.getElementById("serialcase");
				keycodesharp	= document.getElementById("keycodesharp");

				//init...
				serialtype.size		 = 1;
				serialtype.maxLength = serialtype.size;

				serialcase.size		 = 1;
				serialcase.maxLength = serialcase.size;

				keycodesharp.size	   = 1;
				keycodesharp.maxLength = keycodesharp.size;
			}

			function checkvalue(field) {
				keycodesharp.value	= keycodesharp.value.toUpperCase();
				serialcase.value	= serialcase.value.toUpperCase();
				serialtype.value	= serialtype.value.toUpperCase();

				if (field == 'serialtype') {
					if (serialtype.value != 'L' && serialtype.value != 'C' && serialtype.value != 'A' && serialtype.value != '') {
						alert('Kies L voor letter, C voor cijfer, A voor allebij');
						serialtype.value = 'A';
					}
				} else if (field == 'serialcase') {
					if (serialcase.value != 'H' && serialcase.value != 'K' && serialcase.value != 'A' && serialcase.value != '') {
						alert('Kies H voor hooftletters, C voor kleine letters, A voor allebij');
						serialcase.value = 'A';
					}
				} else if (field == 'keycodesharp') {
					if (keycodesharp.value != 'J' && keycodesharp.value != 'N' && keycodesharp.value != '') {
						alert('Kies J voor een keycode met * en # en N voor zonder.');
						keycodesharp.value = '';
					}
				}
			}

			window.onload = init;

		//-->
		//<!]]>
		</script>

		<style type="text/css">

			#container {
				margin: 2px;
				margin-top: 1px !important;
				padding: 10px;
				width: 450px;
				font-family: verdana, Arial, sans-serif;
				font-size: 14px;
				color: #000000;
				background-color: #FCFCFC;
				border: 1px dashed #CCCCCC;
				float: left;
				height: 600px;
				min-height: 500px;
			}

			#container2 {
				margin: 2px;
				margin-top: 1px !important;
				padding: 10px;
				width: 450px;
				font-family: verdana, Arial, sans-serif;
				font-size: 14px;
				color: #000000;
				background-color: #FCFCFC;
				border: 1px dashed #CCCCCC;
				float: right;
				height: 600px;
				min-height: 500px;
			}

			#tabletitle {
				display: block;
				border: 0px dotted #000000;
				border-bottom-width: 1px;
				font-weight: bold;
				font-size: 19px;
				padding: 2px;
				margin: 2px;
				color: #000000;
				margin-bottom: 5px;
			}

			#tablefooter {
				display: block;
				border: 0px dotted #000000;
				border-top-width: 1px;
				font-weight: bold;
				font-size: 16px;
				color: #000000;
				padding: 2px;
				padding-left: 1px;
				padding-right: 1px;
				margin: 2px;
				margin-top: 5px;
			}

			#serialz {
				display: block;
				color: #000000;
				padding: 2px;
				margin: 2px;
				padding-left: 1px;
				padding-right: 1px;
				font-family: courier-new, courier, "lucida console", monotype;
			}


			label {
				display: block;
				margin-top: 2px;
			}

			table {
				border: 0px;
			}

			td {
				padding-left: 1px;
			}

			td.nothing {
				padding: 0px;
				margin: 0px;
			}

			input {
				background-color: #FCFCFC;
				border: 1px dashed #CCCCCC;
				position: relative;				
			}

			input:focus {
				background-color: #FCFCFC;
				border: 1px dashed gray;
			}

			a.searchplugin {
				color: #000000;
				font-size: 17px;
			}
		
		</style>
	</head>
	<body>
		<div id="container">
			<table>
				<tr>
					<td class="nothing">
						<span id="tabletitle">Serialmaker</span>
					</td>
				</tr>
				<tr>
					<td>
						<form method="post" action="serial.php">
							<input type="hidden" name="code" value="serial" />
							<table>
								<tr>
									<td>
										<label for="format">
											<span title="Aangeven met x, scheiding met - (bijv xx-xxxx-xxx-x)">
												Formaat van serial:
											</span>
										</label>
									</td>
									<td>
										<input type="text" name="format" value="{IN.FORMAT}" />
									</td>
								</tr>
								<tr>
									<td>	
										<label for="i">
											<span title="Hoeveel serials te genereren?">
												Aantal generaties:
											</span>
										</label>
									</td>
									<td>
										<input type="text" name="i" value="{IN.I}" />
									</td>
								</tr>
								<tr>
									<td>
										<label for="type">
											<span title="Letters, cijfers, of allebij? (kies L, C of A)">
												Type serial:
											</span>
										</label>
									</td>
									<td>
										<input type="text" name="type" onchange="checkvalue('serialtype');" id="serialtype" value="{IN.TYPE}" />
									</td>
								</tr>
								<tr>
									<td>
										<label for="case">
											<span title="Serial in hoofdletters? (kies H, K of A)">
												Hooftletters?:
											</span>
										</label>
									</td>
									<td>
										<input type="text" name="case" onchange="checkvalue('serialcase');" id="serialcase" value="{IN.CASE}" />
									</td>
								</tr>
								<tr>
									<td colspan="2">
										<input type="submit" value="Verzenden" />
									</td>
								</tr>
							</table>
						</form>
					</td>
				</tr>
				<tr>
					<td class="nothing">
						<span id="tablefooter">
							Serials:
						</span>
						<span id="serialz">
							{OUT.SERIALS}
						</span>
					</td>
				</tr>
			</table>
		</div>
		<div id="container">
			<table>
				<tr>
					<td class="nothing">
						<span id="tabletitle">KeyCodeMaker</span>
					</td>
				</tr>
				<tr>
					<td>
						<form method="post" action="serial.php">
							<input type="hidden" name="code" value="keycode" />
							<table>
								<tr>
									<td>
										<label for="j">
											<span title="Hoeveel nummers moet de keycode bevatten?">
												Aantal nummers:
											</span> 
										</label>
									</td>
									<td>
										<input type="text" name="j" size="1" maxlength="1" value="{IN.J}" />
									</td>
								</tr>
								<tr>
									<td>
										<label>
											<span title="Hoeveel keycodes te genereren?">
												Aantal generaties:
											</span>
										</label>
									</td>
									<td>
										<input type="text" name="i" size="3" maxlength="5" value="{IN.I}" />
									</td>
								</tr>
								<tr>
									<td>
										<label>
											<span title="Mag het # of * bevatten? (kies J of N)">
												Met * en #:
											</span>
										</label>
									</td>
									<td>
										<input type="text" name="sharp" onchange="checkvalue('keycodesharp');" id="keycodesharp" value="{IN.SHARP}" />
									</td>
								</tr>
								<tr>
									<td colspan="2">
										<input type="submit" value="Verzenden" />
									</td>
								</tr>
							</table>
						</form>
					</td>
				</tr>
				<tr>
					<td class="nothing">
						<span id="tablefooter">
							Keycodes:
						</span>
						<span id="serialz">
							{OUT.KEYCODES}
						</span>
					</td>
				</tr>
			</table>
		</div>
	</body>
</html>
EOF;
		return $out;
	}

	public static function parse_incoming() {
		$IN = array();

		foreach ($_GET as $k => $v) {
			if (get_magic_quotes_gpc()) {
				if (is_array($k)) {
					foreach($k as $kk => $vv) {
						$IN[ $k ][ $kk ] = stripslashes($vv);
					}
				} else {
					$IN[ $k ] = stripslashes($v);
				}
			} else {
				if (is_array($k)) {
					foreach($k as $kk => $vv) {
						$IN[ $k ][ $kk ] = $vv;
					}
				} else {
					$IN[ $k ] = $v;
				}
			}
		}

		foreach ($_POST as $k => $v) {
			if (get_magic_quotes_gpc()) {
				if (is_array($k)) {
					foreach($k as $kk => $vv) {
						$IN[ $k ][ $kk ] = stripslashes($vv);
					}
				} else {
					$IN[ $k ] = stripslashes($v);
				}
			} else {
				if (is_array($k)) {
					foreach($k as $kk => $vv) {
						$IN[ $k ][ $kk ] = $vv;
					}
				} else {
					$IN[ $k ] = $v;
				}
			}
		}

		return $IN;
	}

} //einde class

?>[/code]