Jump to content
  • 0

Ban Account using PHP/MYSQL


Yum

Question


  • Group:  Members
  • Topic Count:  13
  • Topics Per Day:  0.00
  • Content Count:  27
  • Reputation:   3
  • Joined:  02/17/12
  • Last Seen:  

Hello,
 
I'm trying to make the ban on an account through my php. I am not knowing generate the correct value for unban_time ...

Using the basis of Ceres I got this:

DEFINE('PARTNER_BAN', "UPDATE `login` SET `unban_time` = NOW() + '%d' WHERE `account_id` = '%d' AND `unban_time` = '0'");

What is the value of %d?


if (isset($GET_frm_name) && isset($GET_id)) {
	$query = sprintf(ACCOUNTS_SEARCH_ACCOUNT_ID, trim($GET_id));
	$result = execute_query($query, 'adminaccban.php');
	if ($line = $result->fetch_row()) {
		$today = getdate();
		
		if (notnumber($GET_id))
			alert($lang['INCORRECT_CHARACTER']);

		if ($GET_bday == $today['mday'] && $GET_bmonth == $today['mon'] && $GET_byear == $today['year'])
			$ban = 0;
		else 
			$ban = truedate($GET_bday, $GET_bmonth, $GET_byear);

		if ($ban <= time())
			$ban = 0;
		
		if ($GET_block == 5)
			$ban = 0;

		if ($_SESSION[$CONFIG_name.'level'] <= $line[4] || ($line[4] >= $_SESSION[$CONFIG_name.'level'] && $_SESSION[$CONFIG_name.'level'] != 99)) {
			$ban = $line[6];
			$GET_block = $line[7];
		}

		$query = sprintf(ACCBAN_UPDATE, $ban, $GET_block, trim($GET_id));
		$result = execute_query($query, 'adminaccban.php');

		alert("Account Updated");
	}
}
function truedate($day, $month, $year) {
	$diames = array (
		1  => 31,
		2  => 28,
		3  => 31,
		4  => 30,
		5  => 31,
		6  => 30,
		7  => 31,
		8  => 31,
		9  => 30,
		10 => 31,
		11 => 30,
		12 => 31,
	);
	if (($year % 4) === 0)
		$diames[2] = 29;

	if ($day > $diames[$month])
		return 0;

	return mktime(0, 0, 0, $month, $day, $year);
}

 

Edited by Yum
Link to comment
Share on other sites

5 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  2
  • Reputation:   0
  • Joined:  12/14/14
  • Last Seen:  

Esse %d indica que a string vai passar por uma formatação, onde o valor indicado será substituido por um inteiro. Esse tipo de formatação é usado no sprintf, cujo valor a ser substituido é informado nos argumentos seguintes respectivamente.

 

Usando como exemplo uma linda do mesmo código mostrado:

$query = sprintf(ACCBAN_UPDATE, $ban, $GET_block, trim($GET_id));

ACCBAN_UPDATE, também foi definido, possivelmente com uma string similar ao PARTNER_BAN que foi mostrado.

onde os valores dos '%d" representados seriam, $ban, $GET_block e trim($GET_id)

 

Então, caso você siga a usar o PARTNER_BAN em algum caso, você deve informar os valores a serem substituidos. %d indica que será um valor inteiro, então não pode ser string. Ou seja, terá que indicar o tempo de ban e o id da conta que irá sofrer a mudança.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  13
  • Topics Per Day:  0.00
  • Content Count:  27
  • Reputation:   3
  • Joined:  02/17/12
  • Last Seen:  

Eu acho que entendi isso antes mesmo de tu explicar, veja essa query abaixo:

DEFINE('PARTNER_BAN', "UPDATE `login` SET `unban_time` = NOW() + '%d' WHERE `account_id` = '%d' AND `unban_time` = '0'");

Obviamente o %d que vem depois do `account_id`= é o trim($GET_id), no entanto, qual o valor do %d que vem depois do NOW()+ ? É o $ban... Mas o que tem dentro disso?

Eu não entendi essa matemática dai, matando essa xarada eu termino o script. Hoje cedo eu dei ban em alguém e ficou assim no unban_time: 1418662291

Usando o getdate eu cheguei a um valor bem parecido (1418576300), isso no php... Porém, como eu faço a soma dos dias? Como eu faço um calculo que retorno o valor correto para a coluna unban_time ?

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  2
  • Reputation:   0
  • Joined:  12/14/14
  • Last Seen:  

Ah sim, o getdate() por padrão retorna o valor em segundos, desde a criação do UNIX, de acordo com o manual do php. Então a modificação do tempo de ban será feita em segundos. Por exemplo, um dia demoraria em torn de 86400 segundos, fazendo essa adição, tem-se o tempo de ban.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  13
  • Topics Per Day:  0.00
  • Content Count:  27
  • Reputation:   3
  • Joined:  02/17/12
  • Last Seen:  

Solved!
 

$dias = $_POST['days'];
$days = $dias * 86400;
$today = getdate();
$ban = $today['0'] + $days;
Link to comment
Share on other sites


  • Group:  Developer
  • Topic Count:  153
  • Topics Per Day:  0.03
  • Content Count:  2285
  • Reputation:   745
  • Joined:  06/16/12
  • Last Seen:  

ENGLISH!!!!!! /bzz

  • Upvote 1
Link to comment
Share on other sites

×
×
  • Create New...