<?php
function deaddslashes(&$str) {
	if (is_array($str))
		foreach ($str as $key => $v)
			deaddslashes($str[$key]);
	elseif (is_string($str))
		$str = stripslashes($str);
}

if (get_magic_quotes_gpc())	{
	deaddslashes($_GET);
	deaddslashes($_POST);
	deaddslashes($_COOKIE);
	deaddslashes($_REQUEST);
}

if(!is_file('install.lock')) {
	$mem = new memcache;
	if(@$mem->connect($_POST['server'], $_POST['port']+0)) {
		$mem->close();
		// --- 高性能缓存连接成功，写入数据 ---
		$slexInfo = file_get_contents('../confs/slex.i.php');
		$slexInfo = preg_replace('/_SLEX\\[\'mmc\'\\].+?\\);/s', "_SLEX['mmc'] = array(
'service' => 'xMemcache',
'host' => '".$_POST['server']."',
'port' => '".$_POST['port']."',
'timeout' => 30,
'pconnect' => false
);", $slexInfo);
		file_put_contents('../confs/slex.i.php', $slexInfo);
		echo json_encode(array(
			'result' => '1'
		));
	} else {
		echo json_encode(array(
			'result' => '0',
			'msg' => 'Memcache 服务器连接失败，请检查 Memcache 服务是否已经正确安装'
		));
	}
}

