Here's where I'm trying to get the ID
function addCliente($tipo_pessoa, $popup=null, $dados = null) {
$tipo_login = $this->session->userdata('tipo_login');
if ($this->session->userdata('logado') == true && $tipo_login == '1') {
$this->load->library('form_validation');
if ($tipo_pessoa == 1) {
$this->form_validation->set_rules('cpf', 'CPF', 'required|callback_verifica_cpf');
} else if ($tipo_pessoa == 2) {
$this->form_validation->set_rules('cnpj', 'CNPJ', 'required|callback_verifica_cnpj');
}
if ($this->form_validation->run() == FALSE) {
$this->returnCadCliente($tipo_pessoa);
} else {
$id_endereco = $this->cadEndereco($tipo_pessoa);
if ($tipo_pessoa == '1') {
$id_pessoa = $this->cadPessoaFisica();
$id_banco = $this->cadastroDadosBancarios();
$id_contato = $this->cadastroContato();
$id_cadastroAnexo = $this->cadastroAnexo();
$id_cadastroAtendimento = $this->cadastroAtendimento();
} else if ($tipo_pessoa == '2') {
$id_pessoa = $this->cadPessoaJuridica();
$id_banco = $this->cadastroDadosBancarios();
$id_contato = $this->cadastroContato();
$id_cadastroAnexo = $this->cadastroAnexo();
$id_cadastroAtendimento = $this->cadastroAtendimento();
}
$limite_credito = null;
if ($this->input->post('limite_credito')) {
$limite_credito = $this->input->post('limite_credito');
}
$id_cliente = $this->cadCliente($tipo_pessoa);
$data_cad = date("d/m/Y");
$hora_cad = date("H:i:s");
if ($id_cadastro = $this->cadastroComum($limite_credito, (int) $tipo_pessoa, $id_pessoa, 1, $id_cliente, $id_endereco, $data_cad, $hora_cad)) {
$this->cadastroHistorico('Cliente cadastrado', $id_cadastro, $data_cad, $hora_cad);
if ($popup == '1') {
$this->mensagemAlerta("Cliente cadastrado com sucesso!", 1, "home/cadastroOrcamentoVenda/" . $this->input->post('matricula'), (int) $tipo_pessoa);
} else {
//$this->mensagemAlerta("Cliente cadastrado com sucesso!", 1, "home/cadastroCliente/", (int) $tipo_pessoa);
I call alteraçãoClientePf here
$this->mensagemAlerta("Cliente cadastrado com sucesso!", 1, "home/alteracaoClientePf/" . $this->input->post('id_cadastro'), (int) $tipo_pessoa);
}
} else {
$this->mensagemAlerta("Erro ao cadastrar cliente, tente novamente!", 0, "cadastro/returnCadCliente/", (int) $tipo_pessoa);
}
}
} else {
$dados['mensagem'] = null;
$this->load->view('login/head');
$this->load->view('login/formLogin', $dados);
$this->load->view('login/footer');
}
}
This is the function I call when requesting the ID
function alteracaoClientePf($id_cadastro, $dados = null) {
$tipo_login = $this->session->userdata('tipo_login');
if ($this->session->userdata('logado') == true && $tipo_login == '1') {
$dadosCliente['dados'] = $this->lista->retornaDadosClientePf($id_cadastro);
$dadosCliente['banco'] = $this->adm->returnBancos();
$dadosCliente['contas_bancarias'] = $this->lista->retornaContas($id_cadastro);
$dadosCliente['contatos'] = $this->lista->retornaContatos($id_cadastro);
$dadosCliente['anexos'] = $this->lista->retornaAnexos($id_cadastro);
$dadosCliente['atendimentos'] = $this->lista->retornaAtendimentos($id_cadastro);
$dadosCliente['historico'] = $this->lista->retornaHistorico($id_cadastro);
$this->load->view('admin/head');
$dadosBarra['dadosB'] = $this->financeiro->listaContas();
$this->load->view('admin/barraSuperior', $dadosBarra);
$dadosLogo['logo'] = $this->adm->retornaLogo();
$this->load->view('admin/menu', $dadosLogo);
$this->load->view('admin/alteracoes/alterar_cliente_pf', $dadosCliente);
$this->load->view('admin/footer');
} else {
$dados['mensagem'] = null;
$this->paginas($dados);
}
}
That's the error I'm getting
Message: Too few arguments to function Home::alteracaoClientePf(), 0 passed in C:\xampp\htdocs\sistema_financas_old_atual\system\core\CodeIgniter.php on line 532 and at least 1 expected
Filename: C:\xampp\htdocs\sistema_financas_old_atual\application\controllers\Home.php
Line Number: 1184
Hello world I'm new so sorry for my question. but I need your help
I have this code
public function GetSyncTransaksi ($ip_add_Get,$DBIDGet='db_ique',$table_get='transaksi') {
$temp_get = NULL;
if ($DBIDGet == 'db_ique') {
$dbhost_get = $ip_add_Get;
$dbuser_get = USER_CABANG; //Harus diganti
$dbpwd_get = PASS_CABANG; //Harus diganti
$dbname_get = $DBIDGet;
} else {
$dbhost_get = $ip_add_Get;
$dbuser_get = USER_PUSAT; //Harus diganti
$dbpwd_get = PASS_PUSAT; //Harus diganti
$dbname_get = "ique_".$DBIDGet;
}
R::addDatabase($dbname_get, 'mysql:host='.$dbhost_get.';dbname='.$dbname_get, $dbuser_get, $dbpwd_get, TRUE);
R::selectDatabase($dbname_get);
$qget = "SELECT * FROM sync_$table_get";
$temp_get = R::getAll($qget);
return $temp_get;
}
public function UpdateSyncTransaksi ($ip_add,$DBID='db_ique',$table='transaksi') {
$temp = NULL;
if ($DBID == 'db_ique') {
$dbhost = $ip_add;
$dbuser = USER_CABANG;
$dbpwd = PASS_CABANG;
$dbname = $DBID;
} else {
$dbhost = $ip_add;
$dbuser = USER_PUSAT;
$dbpwd = PASS_PUSAT;
$dbname = "ique_".$DBID;
}
R::addDatabase($dbname, 'mysql:host='.$dbhost.';dbname='.$dbname, $dbuser, $dbpwd, TRUE);
R::selectDatabase($dbname);
$q = "TRUNCATE TABLE sync_$table";
$temp = R::exec($q);
$q = "INSERT INTO sync_$table SELECT tanggal,COUNT(*) FROM $table GROUP BY tanggal";
$temp = R::exec($q);
return $temp;
}
And I call to this Function
public function CompareSyncTransaksi ($server,$id,$table='transaksi') {
$difference = NULL;
$updatesynccabang = $this->UpdateSyncTransaksi($server,'db_ique',$table); //Update sync_transaksi cabang
$updatesyncpusat = $this->UpdateSyncTransaksi("localhost",$id,$table); //Update sync_transaksi pusat
$synccabang = $this->GetSyncTransaksi($server,'db_ique',$table);
$syncpusat = $this->GetSyncTransaksi("localhost",$id,$table);
$tglcabang = NULL;
if ($synccabang != NULL) {
foreach ($synccabang as $temp) {
$tglcabang[] = $temp->tanggal;
}
}
$tglpusat = NULL;
if ($syncpusat != NULL) {
foreach ($syncpusat as $temp) {
$tglpusat[] = $temp->tanggal;
}
}
$intersect = NULL;
if($tglcabang != NULL && $tglpusat != NULL) {
$difference = array_diff($tglcabang,$tglpusat);
$intersect = array_intersect($tglcabang,$tglpusat);
}
if($intersect != NULL) {
foreach ($intersect as $temp) {
foreach ($synccabang as $temp1) {
if ($temp1->tanggal == $temp) {
$jumlahcabang = $temp1->jumlah;
}
}
foreach ($syncpusat as $temp2) {
if ($temp2->tanggal == $temp) {
$jumlahpusat = $temp2->jumlah;
}
}
if ($jumlahcabang != $jumlahpusat) {
$difference[] = $temp;
}
}
}
if ($difference) {
asort($difference);
}
return $difference;
}
The problem is I got Error "A database has already be specified for this key."
I think the problem is in function GetSyncTransaksi and function UpdateSyncTransaksi.
How can I fix this. please help thank you
Can you please help me to fully convert this class to work with mysqli?
It's a class working on an old system, I just want to make it work with mysqli without having to modify the existing code on all the system.
I tried but with no success.
Thanks in advance!
class BD {
var $sServidor = "host";
var $sBaseDeDatos = "DB";
var $sUsuario = "user";
var $sClave = "pass";
function Conectar() {
if (($this->sServidor != "") && ($this->sUsuario != "")) {
$this->oConexion = mysql_connect($this->sServidor, $this->sUsuario, $this->sClave);
mysql_select_db($this->sBaseDeDatos, $this->oConexion);
mysql_set_charset("utf8", $this->oConexion);
}
}
function RetornarConexion() {
return $this->oConexion;
}
function Seleccionar($pSQL, $pRetornarFila = false) {
$oResultado = $this->Ejecutar($pSQL);
return (($pRetornarFila) ? $this->RetornarFila($oResultado) : $oResultado);
}
function RetornarFila($pResultado) {
return mysql_fetch_array($pResultado);
}
function ContarFilas($pResultado) {
$lFilas = 0;
if ($pResultado) {
$lFilas = mysql_num_rows($pResultado);
}
return $lFilas;
}
function Ejecutar($pSQL) {
$this->Conectar();
$oResultado = mysql_query($pSQL, $this->oConexion);
if ($oResultado) {
if (strpos(strtoupper($pSQL), "INSERT INTO") !== false) {
$oResultado = mysql_insert_id();
} else if (strpos(strtoupper($pSQL), "UPDATE") !== false) {
$oResultado = mysql_affected_rows();
}
}
return $oResultado;
}
function RetornarTipo($pResultado, $pCampo) {
$sTipo = "";
if ($pResultado) {
$sTipo = mysql_field_type($pResultado, $pCampo);
}
return $sTipo;
}
function RetornarLongitud($pResultado, $pCampo) {
$lLongitud = 0;
if ($pResultado) {
$lLongitud = mysql_field_len($pResultado, $pCampo);
}
return $lLongitud;
}
function Desconectar() {
mysql_close($this->oConexion);
}
}
Okay I'm testing it and think it works okay. Here's the code:
P / D: Sorry for wasting your time. Conclusion: I have to sleep a few more hours per day. Thanks and sorry again.
class BD {
var $sServidor = "host";
var $sBaseDeDatos = "DB";
var $sUsuario = "user";
var $sClave = "pass";
function Conectar() {
if (($this->sServidor != "") && ($this->sUsuario != "")) {
$this->oConexion = mysqli_connect($this->sServidor, $this->sUsuario, $this->sClave);
mysqli_select_db($this->oConexion, $this->sBaseDeDatos);
mysqli_set_charset($this->oConexion, "utf8");
}
}
function RetornarConexion() {
return $this->oConexion;
}
function Seleccionar($pSQL, $pRetornarFila = false) {
$oResultado = $this->Ejecutar($pSQL);
return (($pRetornarFila) ? $this->RetornarFila($oResultado) : $oResultado);
}
function RetornarFila($pResultado) {
return mysqli_fetch_array($pResultado);
}
function ContarFilas($pResultado) {
$lFilas = 0;
if ($pResultado) {
$lFilas = mysqli_num_rows($pResultado);
}
return $lFilas;
}
function Ejecutar($pSQL) {
$this->Conectar();
$oResultado = mysqli_query($this->oConexion, $pSQL);
if ($oResultado) {
if (strpos(strtoupper($pSQL), "INSERT INTO") !== false) {
$oResultado = mysqli_insert_id($this->oConexion);
} else if (strpos(strtoupper($pSQL), "UPDATE") !== false) {
$oResultado = mysqli_affected_rows($this->oConexion);
}
}
return $oResultado;
}
function RetornarTipo($pResultado, $pCampo) {
$sTipo = "";
if ($pResultado) {
$sTipo = mysqli_field_type($pResultado, $pCampo);
}
return $sTipo;
}
function RetornarLongitud($pResultado, $pCampo) {
$lLongitud = 0;
if ($pResultado) {
$lLongitud = mysqli_field_len($pResultado, $pCampo);
}
return $lLongitud;
}
function Desconectar() {
mysqli_close($this->oConexion);
}
}
i have a script named remauth.php
it connects to phpbb database and use some information of users.
its code:
<?php
// standard phpBB setup
if ($_SERVER['REMOTE_ADDR'] == "127.0.0.1" || $_SERVER['REMOTE_ADDR'] == "94.23.147.71" || $_SERVER['REMOTE_ADDR'] == "188.226.149.35")
{
unset($_SERVER['REMOTE_ADDR']);
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_REAL_IP'];
}
if ($_SERVER['HTTP_X_FORWARDED_FOR'] == "127.0.0.1" || $_SERVER['HTTP_X_FORWARDED_FOR'] == "94.23.147.71" || $_SERVER['HTTP_X_FORWARDED_FOR'] == "188.226.149.35")
{
unset($_SERVER['HTTP_X_FORWARDED_FOR']);
}
function get_ip_address()
{
foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key)
{
if (array_key_exists($key, $_SERVER) === true)
{
foreach (explode(',', $_SERVER[$key]) as $ip)
{
if ($_SERVER[$key] == "127.0.0.1" || $_SERVER[$key] == "94.23.147.71" || $_SERVER[$key] == "188.226.149.35")
{
unset($_SERVER[$key]);
}
if (valid_ip($ip) !== false)
{
return $ip;
}
}
}
}
}
get_ip_address();
$acm_type = "memcache";
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
define('IN_PHPBB', true);
define('IN_CHECK_BAN', 1);
define('IN_LOGIN', 1);
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
//include_once($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
if (!function_exists('group_memberships'))
{
include_once($phpbb_root_path . 'includes/functions_user.'.$phpEx);
}
function valid_ip($ip)
{
return (!preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)) ? FALSE : TRUE;
}
$user->session_begin();
$auth->acl($user->data);
$canPlay = false;
function isGroup($userid)
{
$groups = group_memberships(false, $userid);
$return = false;
foreach ($groups as $grouprec)
{
if ($grouprec['group_id'] == 2 || $grouprec['group_id'] == 3 || $grouprec['group_id'] == 4 || $grouprec['group_id'] == 5 || $grouprec['group_id'] == 8 || $grouprec['group_id'] == 9 || $grouprec['group_id'] == 10)
{
$return = true;
}
}
return $return;
}
function get_profile_fields($user_id)
{
global $db;
$sql = 'SELECT *
FROM ' . PROFILE_FIELDS_DATA_TABLE . '
WHERE ' . $db->sql_in_set('user_id', array_map('intval', $user_id));
$result = $db->sql_query($sql);
$field_data = array();
while ($row = $db->sql_fetchrow($result))
{
$field_data[$row['user_id']] = $row;
}
$db->sql_freeresult($result);
$user_fields = array();
$fields = array('can_has_servers', 'can_play', 'can_play_expire', 'can_play_reason');
foreach ($fields as $used_ident)
{
foreach ($field_data as $user_id => $row)
{
$user_fields[$user_id][$used_ident]['value'] = $row['pf_' . $used_ident];
}
}
return $user_fields;
}
function check_ban($user_id = false, $user_ips = false, $user_email = false, $return = false)
{
global $config, $db;
$banned = false;
$cache_ttl = 3600;
$where_sql = array();
$sql = 'SELECT ban_ip, ban_userid, ban_email, ban_exclude, ban_give_reason, ban_end
FROM ' . BANLIST_TABLE . '
WHERE ';
// determine which entries to check, only return those
if ($user_email === false)
{
$where_sql[] = "ban_email = ''";
}
if ($user_ips === false)
{
$where_sql[] = "(ban_ip = '' OR ban_exclude = 1)";
}
if ($user_id === false)
{
$where_sql[] = '(ban_userid = 0 OR ban_exclude = 1)';
}
else
{
$cache_ttl = ($user_id == ANONYMOUS) ? 3600 : 0;
$_sql = '(ban_userid = ' . $user_id;
if ($user_email !== false)
{
$_sql .= " OR ban_email <> ''";
}
if ($user_ips !== false)
{
$_sql .= " OR ban_ip <> ''";
}
$_sql .= ')';
$where_sql[] = $_sql;
}
$sql .= (sizeof($where_sql)) ? implode(' AND ', $where_sql) : '';
$result = $db->sql_query($sql, $cache_ttl);
$ban_triggered_by = 'user';
while ($row = $db->sql_fetchrow($result))
{
if ($row['ban_end'] && $row['ban_end'] < time())
{
continue;
}
$ip_banned = false;
if (!empty($row['ban_ip']))
{
if (!is_array($user_ips))
{
$ip_banned = preg_match('#^' . str_replace('\*', '.*?', preg_quote($row['ban_ip'], '#')) . '$#i', $user_ips);
}
else
{
foreach ($user_ips as $user_ip)
{
if (preg_match('#^' . str_replace('\*', '.*?', preg_quote($row['ban_ip'], '#')) . '$#i', $user_ip))
{
$ip_banned = true;
break;
}
}
}
}
if ((!empty($row['ban_userid']) && intval($row['ban_userid']) == $user_id) ||
$ip_banned ||
(!empty($row['ban_email']) && preg_match('#^' . str_replace('\*', '.*?', preg_quote($row['ban_email'], '#')) . '$#i', $user_email)))
{
if (!empty($row['ban_exclude']))
{
$banned = false;
break;
}
else
{
$banned = true;
$ban_row = $row;
if (!empty($row['ban_userid']) && intval($row['ban_userid']) == $user_id)
{
$ban_triggered_by = 'user';
}
else if ($ip_banned)
{
$ban_triggered_by = 'ip';
}
else
{
$ban_triggered_by = 'email';
}
// don't break. Check if there is an exclude rule for this user
}
}
}
$db->sql_freeresult($result);
if ($banned && !$return)
{
global $template;
// if the session is empty we need to create a valid one...
if (empty($this->session_id))
{
// this seems to be no longer needed? - #14971
//$this->session_create(ANONYMOUS);
}
// initiate environment ... since it won't be set at this stage
$this->setup();
// logout the user, banned users are unable to use the normal 'logout' link
if ($this->data['user_id'] != ANONYMOUS)
{
$this->session_kill();
}
// we show a login box here to allow founders accessing the board if banned by IP
if (defined('IN_LOGIN') && $this->data['user_id'] == ANONYMOUS)
{
global $phpEx;
$this->setup('ucp');
$this->data['is_registered'] = $this->data['is_bot'] = false;
// Set as a precaution to allow login_box() handling this case correctly as well as this function not being executed again.
define('IN_CHECK_BAN', 1);
login_box("index.$phpEx");
// The false here is needed, else the user is able to circumvent the ban.
$this->session_kill(false);
}
// ok, we catch the case of an empty session id for the anonymous user...
// this can happen if the user is logging in, banned by username and the login_box() being called "again".
if (empty($this->session_id) && defined('IN_CHECK_BAN'))
{
$this->session_create(ANONYMOUS);
}
// determine which message to output
$till_date = ($ban_row['ban_end']) ? $this->format_date($ban_row['ban_end']) : '';
$message = ($ban_row['ban_end']) ? 'BOARD_BAN_TIME' : 'BOARD_BAN_PERM';
$message = sprintf($this->lang[$message], $till_date, '', '');
$message .= ($ban_row['ban_give_reason']) ? '<br /><br />' . sprintf($this->lang['BOARD_BAN_REASON'], $ban_row['ban_give_reason']) : '';
$message .= '<br /><br /><em>' . $this->lang['BAN_TRIGGERED_BY_' . strtoupper($ban_triggered_by)] . '</em>';
// to circumvent session_begin returning a valid value and the check_ban() not called on second page view, we kill the session again
$this->session_kill(false);
// a very special case... we are within the cron script which is not supposed to print out the ban message... show blank page
if (defined('IN_CRON'))
{
garbage_collection();
exit_handler();
exit;
}
trigger_error($message);
}
return ($banned && $ban_row['ban_give_reason']) ? $ban_row['ban_give_reason'] : $banned;
}
// session stuff will not be needed as this occurs from a non-client session, but we need $user->setup it seems
if (empty($user->lang))
{
$user->setup();
}
$user->add_lang('ucp');
// get variables
/* $data = request_var('data', '', true);
if (!isset($_GET['username']))
{ */
$data = file_get_contents('php://input');
$data = explode('&&', $data);
$username = trim(htmlspecialchars(str_replace(array("\r\n", "\r", "\0"), array("\n", "\n", ''), $data[0]), ENT_COMPAT, 'UTF-8'));
$password = trim(htmlspecialchars(str_replace(array("\r\n", "\r", "\0"), array("\n", "\n", ''), $data[1]), ENT_COMPAT, 'UTF-8'));
/* }
else
{
$username = $_GET['username'];
$password = $_GET['password'];
} */
// perform login from $auth. we don't want autologon, viewonline nor admin access for the session
$result = $auth->login($username, $password, false, false, false);
if ($result['status'] == LOGIN_SUCCESS)
{
$userID = $user->data['user_id'];
$user_id = array($userID);
$canhave = get_profile_fields($user_id);
if ($canhave[$userID]['can_play_expire']['value'] <= time())
{
$canhave[$userID]['can_play']['value'] = 1;
}
if ($canhave[$userID]['can_play']['value'] == 1 || $canhave[$userID]['can_play']['value'] == 0 || $canhave[$userID]['can_play']['value'] == "")
{
$canPlay = true;
if (true || isGroup($user->data['user_id']))
{
$canPlay = true;
$keysql = "UPDATE phpbb_sessions SET session_onlineplay = 1, session_realip = '".htmlspecialchars(get_ip_address(), ENT_QUOTES)."' WHERE session_id = '".$user->session_id."';";
$keyresult = $db->sql_query($keysql);
$db->sql_freeresult($keyresult);
}
else
{
$result['status'] = 'nope';
$result['error_msg'] = 'triobit is currently down for maintenance.';
}
}
else
{
$result['status'] = 'nope';
//$result['error_msg'] = 'User is not allowed to play';
$result['error_msg'] = 'Online playing privileges revoked';
if ($canhave[$userID]['can_play_reason']['value'])
{
$result['error_msg'] .= ' - ' . str_replace('#', '#', $canhave[$userID]['can_play_reason']['value']);
}
if ($canhave[$userID]['can_play_expire']['value'])
{
$result['error_msg'] .= ' (will expire in ' . duration($canhave[$userID]['can_play_expire']['value'] - time()) . ')';
}
}
$banReason = check_ban($userID, '', '', 1);
if ($banReason != "")
{
$result['status'] = 'nope';
$result['error_msg'] = 'User is banned';
$canPlay = false;
}
}
// start buffering (to allow kill)
ob_start();
// output the results
echo (($result['status'] == LOGIN_SUCCESS) ? 'ok' : 'fail') . '#';
echo (($result['error_msg']) ? ((isset($user->lang[$result['error_msg']])) ? $user->lang[$result['error_msg']] : $result['error_msg']) : 'Success.') . '#';
echo (($result['status'] == LOGIN_SUCCESS) ? $user->data['user_id'] : '1') . '#';
echo (($result['status'] == LOGIN_SUCCESS) ? $user->data['username'] : 'Anonymous') . '#';
echo (($result['status'] == LOGIN_SUCCESS) ? $user->data['user_email'] : 'anonymous#example.com') . '#';
echo (($result['status'] == LOGIN_SUCCESS) ? $user->session_id : '0') . '#';
//Deleted, used for login verify now
// kill the session
if (!$canPlay)
{
$user->session_kill(false);
}
// and flush the contents
ob_end_flush();
exit;
function format_duration($seconds) {
$periods = array(
'centuries' => 3155692600,
'decades' => 315569260,
'years' => 31556926,
'months' => 2629743,
'weeks' => 604800,
'days' => 86400,
'hours' => 3600,
'minutes' => 60,
'seconds' => 1
);
$durations = array();
foreach ($periods as $period => $seconds_in_period) {
if ($seconds >= $seconds_in_period) {
$durations[$period] = floor($seconds / $seconds_in_period);
$seconds -= $durations[$period] * $seconds_in_period;
}
}
return $durations;
}
function duration($seconds) {
$data = format_duration($seconds);
$data2 = array();
foreach ($data as $unit => $amount)
{
$data2[] = $amount . ' ' . $unit;
}
return implode(', ', $data2);
}
?>
and its error
Notice: Undefined index: HTTP_X_FORWARDED_FOR in C:\xnp\htdocs\remauth.php on line 9
Notice: Undefined index: HTTP_X_FORWARDED_FOR in C:\xnp\htdocs\remauth.php on line 9
Notice: Undefined index: HTTP_X_FORWARDED_FOR in C:\xnp\htdocs\remauth.php on line 9
help me please.
Use HTTP_HOST instead of HTTP_X_FORWARDED_FOR
if ($_SERVER['HTTP_HOST'] == "127.0.0.1" || $_SERVER['HTTP_HOST'] == "94.23.147.71" || $_SERVER['HTTP_HOST'] == "188.226.149.35")
{
unset($_SERVER['HTTP_HOST']);
}
function get_ip_address()
{
foreach (array('HTTP_CLIENT_IP', 'HTTP_HOST', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key)
{
if (array_key_exists($key, $_SERVER) === true)
{
foreach (explode(',', $_SERVER[$key]) as $ip)
{
if ($_SERVER[$key] == "127.0.0.1" || $_SERVER[$key] == "94.23.147.71" || $_SERVER[$key] == "188.226.149.35")
{
unset($_SERVER[$key]);
}
if (valid_ip($ip) !== false)
{
return $ip;
}
}
}
}
}
get_ip_address();
$acm_type = "memcache";
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
define('IN_PHPBB', true);
define('IN_CHECK_BAN', 1);
define('IN_LOGIN', 1);
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
//include_once($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
if (!function_exists('group_memberships'))
{
include_once($phpbb_root_path . 'includes/functions_user.'.$phpEx);
}
function valid_ip($ip)
{
return (!preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)) ? FALSE : TRUE;
}
$user->session_begin();
$auth->acl($user->data);
$canPlay = false;
function isGroup($userid)
{
$groups = group_memberships(false, $userid);
$return = false;
foreach ($groups as $grouprec)
{
if ($grouprec['group_id'] == 2 || $grouprec['group_id'] == 3 || $grouprec['group_id'] == 4 || $grouprec['group_id'] == 5 || $grouprec['group_id'] == 8 || $grouprec['group_id'] == 9 || $grouprec['group_id'] == 10)
{
$return = true;
}
}
return $return;
}
function get_profile_fields($user_id)
{
global $db;
$sql = 'SELECT *
FROM ' . PROFILE_FIELDS_DATA_TABLE . '
WHERE ' . $db->sql_in_set('user_id', array_map('intval', $user_id));
$result = $db->sql_query($sql);
$field_data = array();
while ($row = $db->sql_fetchrow($result))
{
$field_data[$row['user_id']] = $row;
}
$db->sql_freeresult($result);
$user_fields = array();
$fields = array('can_has_servers', 'can_play', 'can_play_expire', 'can_play_reason');
foreach ($fields as $used_ident)
{
foreach ($field_data as $user_id => $row)
{
$user_fields[$user_id][$used_ident]['value'] = $row['pf_' . $used_ident];
}
}
return $user_fields;
}
function check_ban($user_id = false, $user_ips = false, $user_email = false, $return = false)
{
global $config, $db;
$banned = false;
$cache_ttl = 3600;
$where_sql = array();
$sql = 'SELECT ban_ip, ban_userid, ban_email, ban_exclude, ban_give_reason, ban_end
FROM ' . BANLIST_TABLE . '
WHERE ';
// determine which entries to check, only return those
if ($user_email === false)
{
$where_sql[] = "ban_email = ''";
}
if ($user_ips === false)
{
$where_sql[] = "(ban_ip = '' OR ban_exclude = 1)";
}
if ($user_id === false)
{
$where_sql[] = '(ban_userid = 0 OR ban_exclude = 1)';
}
else
{
$cache_ttl = ($user_id == ANONYMOUS) ? 3600 : 0;
$_sql = '(ban_userid = ' . $user_id;
if ($user_email !== false)
{
$_sql .= " OR ban_email <> ''";
}
if ($user_ips !== false)
{
$_sql .= " OR ban_ip <> ''";
}
$_sql .= ')';
$where_sql[] = $_sql;
}
$sql .= (sizeof($where_sql)) ? implode(' AND ', $where_sql) : '';
$result = $db->sql_query($sql, $cache_ttl);
$ban_triggered_by = 'user';
while ($row = $db->sql_fetchrow($result))
{
if ($row['ban_end'] && $row['ban_end'] < time())
{
continue;
}
$ip_banned = false;
if (!empty($row['ban_ip']))
{
if (!is_array($user_ips))
{
$ip_banned = preg_match('#^' . str_replace('\*', '.*?', preg_quote($row['ban_ip'], '#')) . '$#i', $user_ips);
}
else
{
foreach ($user_ips as $user_ip)
{
if (preg_match('#^' . str_replace('\*', '.*?', preg_quote($row['ban_ip'], '#')) . '$#i', $user_ip))
{
$ip_banned = true;
break;
}
}
}
}
if ((!empty($row['ban_userid']) && intval($row['ban_userid']) == $user_id) ||
$ip_banned ||
(!empty($row['ban_email']) && preg_match('#^' . str_replace('\*', '.*?', preg_quote($row['ban_email'], '#')) . '$#i', $user_email)))
{
if (!empty($row['ban_exclude']))
{
$banned = false;
break;
}
else
{
$banned = true;
$ban_row = $row;
if (!empty($row['ban_userid']) && intval($row['ban_userid']) == $user_id)
{
$ban_triggered_by = 'user';
}
else if ($ip_banned)
{
$ban_triggered_by = 'ip';
}
else
{
$ban_triggered_by = 'email';
}
// don't break. Check if there is an exclude rule for this user
}
}
}
$db->sql_freeresult($result);
if ($banned && !$return)
{
global $template;
// if the session is empty we need to create a valid one...
if (empty($this->session_id))
{
// this seems to be no longer needed? - #14971
//$this->session_create(ANONYMOUS);
}
// initiate environment ... since it won't be set at this stage
$this->setup();
// logout the user, banned users are unable to use the normal 'logout' link
if ($this->data['user_id'] != ANONYMOUS)
{
$this->session_kill();
}
// we show a login box here to allow founders accessing the board if banned by IP
if (defined('IN_LOGIN') && $this->data['user_id'] == ANONYMOUS)
{
global $phpEx;
$this->setup('ucp');
$this->data['is_registered'] = $this->data['is_bot'] = false;
// Set as a precaution to allow login_box() handling this case correctly as well as this function not being executed again.
define('IN_CHECK_BAN', 1);
login_box("index.$phpEx");
// The false here is needed, else the user is able to circumvent the ban.
$this->session_kill(false);
}
// ok, we catch the case of an empty session id for the anonymous user...
// this can happen if the user is logging in, banned by username and the login_box() being called "again".
if (empty($this->session_id) && defined('IN_CHECK_BAN'))
{
$this->session_create(ANONYMOUS);
}
// determine which message to output
$till_date = ($ban_row['ban_end']) ? $this->format_date($ban_row['ban_end']) : '';
$message = ($ban_row['ban_end']) ? 'BOARD_BAN_TIME' : 'BOARD_BAN_PERM';
$message = sprintf($this->lang[$message], $till_date, '', '');
$message .= ($ban_row['ban_give_reason']) ? '<br /><br />' . sprintf($this->lang['BOARD_BAN_REASON'], $ban_row['ban_give_reason']) : '';
$message .= '<br /><br /><em>' . $this->lang['BAN_TRIGGERED_BY_' . strtoupper($ban_triggered_by)] . '</em>';
// to circumvent session_begin returning a valid value and the check_ban() not called on second page view, we kill the session again
$this->session_kill(false);
// a very special case... we are within the cron script which is not supposed to print out the ban message... show blank page
if (defined('IN_CRON'))
{
garbage_collection();
exit_handler();
exit;
}
trigger_error($message);
}
return ($banned && $ban_row['ban_give_reason']) ? $ban_row['ban_give_reason'] : $banned;
}
// session stuff will not be needed as this occurs from a non-client session, but we need $user->setup it seems
if (empty($user->lang))
{
$user->setup();
}
$user->add_lang('ucp');
// get variables
/* $data = request_var('data', '', true);
if (!isset($_GET['username']))
{ */
$data = file_get_contents('php://input');
$data = explode('&&', $data);
$username = trim(htmlspecialchars(str_replace(array("\r\n", "\r", "\0"), array("\n", "\n", ''), $data[0]), ENT_COMPAT, 'UTF-8'));
$password = trim(htmlspecialchars(str_replace(array("\r\n", "\r", "\0"), array("\n", "\n", ''), $data[1]), ENT_COMPAT, 'UTF-8'));
/* }
else
{
$username = $_GET['username'];
$password = $_GET['password'];
} */
// perform login from $auth. we don't want autologon, viewonline nor admin access for the session
$result = $auth->login($username, $password, false, false, false);
if ($result['status'] == LOGIN_SUCCESS)
{
$userID = $user->data['user_id'];
$user_id = array($userID);
$canhave = get_profile_fields($user_id);
if ($canhave[$userID]['can_play_expire']['value'] <= time())
{
$canhave[$userID]['can_play']['value'] = 1;
}
if ($canhave[$userID]['can_play']['value'] == 1 || $canhave[$userID]['can_play']['value'] == 0 || $canhave[$userID]['can_play']['value'] == "")
{
$canPlay = true;
if (true || isGroup($user->data['user_id']))
{
$canPlay = true;
$keysql = "UPDATE phpbb_sessions SET session_onlineplay = 1, session_realip = '".htmlspecialchars(get_ip_address(), ENT_QUOTES)."' WHERE session_id = '".$user->session_id."';";
$keyresult = $db->sql_query($keysql);
$db->sql_freeresult($keyresult);
}
else
{
$result['status'] = 'nope';
$result['error_msg'] = 'triobit is currently down for maintenance.';
}
}
else
{
$result['status'] = 'nope';
//$result['error_msg'] = 'User is not allowed to play';
$result['error_msg'] = 'Online playing privileges revoked';
if ($canhave[$userID]['can_play_reason']['value'])
{
$result['error_msg'] .= ' - ' . str_replace('#', '#', $canhave[$userID]['can_play_reason']['value']);
}
if ($canhave[$userID]['can_play_expire']['value'])
{
$result['error_msg'] .= ' (will expire in ' . duration($canhave[$userID]['can_play_expire']['value'] - time()) . ')';
}
}
$banReason = check_ban($userID, '', '', 1);
if ($banReason != "")
{
$result['status'] = 'nope';
$result['error_msg'] = 'User is banned';
$canPlay = false;
}
}
// start buffering (to allow kill)
ob_start();
// output the results
echo (($result['status'] == LOGIN_SUCCESS) ? 'ok' : 'fail') . '#';
echo (($result['error_msg']) ? ((isset($user->lang[$result['error_msg']])) ? $user->lang[$result['error_msg']] : $result['error_msg']) : 'Success.') . '#';
echo (($result['status'] == LOGIN_SUCCESS) ? $user->data['user_id'] : '1') . '#';
echo (($result['status'] == LOGIN_SUCCESS) ? $user->data['username'] : 'Anonymous') . '#';
echo (($result['status'] == LOGIN_SUCCESS) ? $user->data['user_email'] : 'anonymous#example.com') . '#';
echo (($result['status'] == LOGIN_SUCCESS) ? $user->session_id : '0') . '#';
//Deleted, used for login verify now
// kill the session
if (!$canPlay)
{
$user->session_kill(false);
}
// and flush the contents
ob_end_flush();
exit;
function format_duration($seconds) {
$periods = array(
'centuries' => 3155692600,
'decades' => 315569260,
'years' => 31556926,
'months' => 2629743,
'weeks' => 604800,
'days' => 86400,
'hours' => 3600,
'minutes' => 60,
'seconds' => 1
);
$durations = array();
foreach ($periods as $period => $seconds_in_period) {
if ($seconds >= $seconds_in_period) {
$durations[$period] = floor($seconds / $seconds_in_period);
$seconds -= $durations[$period] * $seconds_in_period;
}
}
return $durations;
}
function duration($seconds) {
$data = format_duration($seconds);
$data2 = array();
foreach ($data as $unit => $amount)
{
$data2[] = $amount . ' ' . $unit;
}
return implode(', ', $data2);
}
I'am getting:
Fatal error: Call to a member function num_rows() on a non-object in /home/nbaxy/public_html/application/core/MY_Controller.php on line 137
MY_Controller.php:
<?php
class MY_Controller extends CI_Controller
{
private $dblabg = array();
public function __construct()
{
parent::__construct();
if($this->config->item("use_database") == 1)
{
$this->load->database();
$this->load->model("dashboard/admin");
$this->set_config();
if($this->config->item("module_user_online") == 1 )
{
$this->set_online();
}
}
$this->set_lang();
$this->clean_cache();
if($this->router->fetch_module() == 'dashboard')
{
$this->__dashboard();
}
}
protected function set_lang()
{
if($this->config->item("user_change_lang") == "1")
{
if($this->input->get("lang"))
{
if(in_array($this->input->get("lang"),$this->config->item("langs_available")) || $this->config->item("use_db_language") == '1')
{
$this->config->set_item("lang",$this->input->get("lang"));
$this->session->set_userdata('lang', $this->input->get("lang"));
}
}
else
{
if($this->session->userdata('lang') != '')
{
$this->config->set_item("lang",$this->session->userdata('lang'));
}
else
{
if($this->config->item("language_browser") == '1' )
{
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
$temp = $this->admin->getTable('languages',array("iso" => $lang));
if($temp->num_rows()>0 && $this->config->item("language_browser") == '1' && $this->router->fetch_module() != 'dashboard')
{
$d = $temp->row();
$this->config->set_item("lang",$d->language);
}
}
}
}
}
if($this->config->item("use_db_language") == '1')
{
$this->load_db_language($this->config->item("lang"));
}
else
$this->lang->load($this->config->item("lang"),$this->config->item("lang"));
}
public function load_db_language($lang = 'english')
{
$this->db->select ('*');
$this->db->from ('language');
$this->db->where ('language', $lang);
$query = $this->db->get()->result();
foreach ( $query as $row )
{
$return[$row->key] = $row->text;
}
$this->dblabg = $return;
$this->db->select ('*');
$this->db->from ('languages');
$query = $this->db->get()->result();
$return = array();
foreach ( $query as $row )
{
$return[$row->language] = $row->language;
}
$this->config->set_item("langs_available", $return);
unset($query,$return);
}
public function get_label($key)
{
return $this->dblabg[$key];
}
protected function clean_cache()
{
if(exec('echo EXEC') == 'EXEC')
{
if($this->config->item("clean_cache") != '0')
{
exec("find ".getcwd()." -type f -name '*.cache' -mtime +".$this->config->item("clean_cache")." -exec rm {} \;");
}
}
}
protected function set_online()
{
$this->admin->setUsuarioOnline(intval($this->session->userdata('id')));
}
protected function set_config()
{
$config = $this->admin->getTable("settings");
if($config->num_rows() == 0)
{
show_error("No settings founds in your database, you need install this script on clean database",400);
}
foreach ($config->result_array() as $row)
{
if($row['var'] != 'use_database')
{
if($row['var'] == 'langs_available')
{
$this->load->helper('directory');
$langs = directory_map('./application/language');
foreach ($langs as $key => $value) {
$temp[] = $key;
}
$row['value'] = $temp;
}
if($row['var'] == 'theme')
{
if($_GET['skin'])
{
$row['value'] = $_GET['skin'];
}
}
if(!is_array($row['value']))
{
//$row['value'] = str_ireplace('"', "'",$row['value']);
$row['value'] = str_ireplace('\"', '"',$row['value']);
$row['value'] = str_ireplace("\'", "'",$row['value']);
$row['value'] = html_entity_decode($row['value']);
}
$this->config->set_item($row['var'], $row['value']);
if($this->agent->is_mobile())
{
$this->config->set_item("theme", $this->config->item("theme_mobile"));
}
}
}
if($this->agent->is_mobile())
{
if($this->config->item("mobile_redirect") != '')
redirect($this->config->item("mobile_redirect"), 'location', 301);
}
if(is_logged())
{
$this->config->set_item("biography_lang_temp",$this->config->item("biography_lang"));
$this->config->set_item("biography_lang", $this->session->userdata('biography_lang'));
}
$config = Array(
'protocol' => 'smtp',
'smtp_host' => $this->config->item("smtp_host"),
'smtp_port' => $this->config->item("smtp_port"),
'smtp_user' => $this->config->item("smtp_user"), // change it to yours
'smtp_pass' => $this->config->item("smtp_pass"), // change it to yours
'mailtype' => 'html',
'charset' => 'utf-8',
'wordwrap' => TRUE
);
$this->load->library('email',$config);
}
protected function __dashboard()
{
if($this->config->item("use_database") == 0)
{
show_404();
}
if(!is_logged() && $this->router->method != 'login' && $this->router->method != 'logout' )
{
redirect(base_url()."dashboard/login");
}
if($this->session->userdata('is_admin') != 1 && $this->router->method != 'login')
{
//redirect(base_url(),"refresh");
redirect(base_url()."dashboard/login");
}
else{
if($this->session->userdata('username') == 'demo#jodacame.com' && $this->router->method != 'login')
{
if($this->router->method == 'website')
{
$this->config->set_item("lastfm", 'lastfmdemomodeapikey');
}
if($_POST || $this->router->method == 'smtp' || $this->router->method == 'license' || $this->router->method =='users' || $this->router->method =='lyrics' || $this->router->method == 'newsletter' )
{
show_error("Demo Account don't have permission for this action",403);
}
}
// Upgrade
if(file_exists("upgrade/upgrade.sql"))
{
$MD5 = md5_file("upgrade/upgrade.sql");
if($this->config->item("md5updated") != $MD5)
{
$sql = file_get_contents("upgrade/upgrade.sql");
$sqls = explode(";\n",$sql);
foreach ($sqls as $key => $value) {
if($value != '')
{
$this->db->query($value);
//echo $this->db->last_query()."<br>";
}
}
$this->db->query("UPDATE settings SET value = '$MD5' WHERE var='md5updated';");
$this->session->sess_destroy();
//echo $this->db->last_query()."<br>";
redirect(base_url()."dashboard/login/1");
}
}
if(file_exists("install.sql"))
{
$sql = file_get_contents("install.sql");
$sqls = explode(";\n",$sql);
foreach ($sqls as $key => $value) {
if($value != '')
{
$this->db->query($value);
//echo $this->db->last_query()."<br>";
}
}
unlink("install.sql");
redirect(base_url()."dashboard/login/2");
}
// Check install modules
}
}
}
Please tell me, how can i fix this?
The problem is you are calling "$temp->num_rows()" Your Variable $temp is not a result set from a Database Query. You are calling a method that doesn't exist. It seems you are trying to get the number of rows of data that are on the table 'languages'. In this case you would need to execute a $SQL query.
Example:
// this assumes $mysqli is a successfull connection to the table 'languages'
$query = "SELECT COUNT(id) FROM `languages`";
if ($result = $mysqli->query($query)) {
$row_cnt = $result->num_rows; //$row_cnt now equals an integer.
}
*Note: You need to replace $temp->numrows with if($row_cnt > 0...)