Location: PHPKode > projects > YASeMI > yasemi_0.1/gs/insert_subnet.php
<?php

	// INCLUDE VARIOUS SCRIPTS
	include 'dbc.php';

	session_start();
	
	$ip_parts = split("\.",$_POST["subnet"]);
	
	if ($ip_parts[0] != 10 && $ip_parts[0] != 192 && $ip_parts[0] != 172)
		$_SESSION["error"] = '<span style="color: red;">Invalid ip format or range1.</span><br>';
	else if (($ip_parts[1] < 0 || $ip_parts[1] > 255) || ($ip_parts[0] == 172 && ($ip_parts[1] < 16 || $ip_parts[1] > 31)) || 
			($ip_parts[0] == 192 && $ip_parts[1] != 168 ))
		$_SESSION["error"] = '<span style="color: red;">Invalid ip format or range2.</span><br>';
	else if ($ip_parts[2] < 0 || $ip_parts[2] > 255)
		$_SESSION["error"] = '<span style="color: red;">Invalid ip format or range3.</span><br>';
		
	if (!empty($_SESSION["error"])) {
	  header("Location: ../settings.php");
	  exit;
	}
	
	// CONNECT TO THE DATABASE
	$link_id = db_connect();
	
	// INSERT THE SUBNET INTO THE DB
	$query = "INSERT INTO settings (settings_subnet) VALUES ('".mysql_real_escape_string($_POST["subnet"])."')";

	$result = mysql_query($query) or die(mysql_error().'<br> SQL:'.$query);
	
	// CLOSE THE DB CONNECTION
	mysql_close($link_id);
	
	unset($_SESSION["error"]);

	// CLEAR SESSION VARIABLES ARRAY
	$_SESSION = array();

	// DESTROY THE SESSION
	session_destroy();
	
	header("Location: ../settings.php");

?>
Return current item: YASeMI