I've got this basic function as below:
function buy()
{
$item_id = ( int )$this->uri->segment( 3 );
if ( $item_id > '0' )
{
$item = $this->db->where( 'shop_id', $item_id )->get( 'shop' )->row();
if ( $item )
{
$player = $this->user->info( $this->user->id() );
if ( $player->users_money >= $item->shop_req_money && $player->users_credits >= $item->shop_req_credits)
{
$this->db->update( 'users_items', array( 'users_id' => $this->user->id(), 'users_motors_id' => '0' ), array( 'users_items_id' => $item->users_items_id ) );
$this->db->update( 'users', array( 'users_money' => $player->users_money - $item->shop_req_money, 'users_credits' => $player->users_credits - $item->shop_req_credits ), array( 'users_id' => $this->user->id() ) );
$this->db->query( 'UPDATE users SET users_money=users_money+' . $item->shop_req_money . ', users_credits=users_credits+' . $item->shop_req_credits . ' WHERE users_id=' . $this->db->escape( $item->shop_users_id ) );
$this->db->delete( 'shop', array( 'shop_id' => $item->shop_id ) );
$this->session->set_flashdata( 'success', true );
}
else
$this->session->set_flashdata( 'error', true );
}
}
header( 'Location: ' . $_SERVER['HTTP_REFERER'] );
}
and I edited it like that to add additional check if the reg ip isn't the same as the other one and if so to set an error message.
function buy()
{
$item_id = ( int )$this->uri->segment( 3 );
if ( $item_id > '0' )
{
$item = $this->db->where( 'shop_id', $item_id )->get( 'shop' )->row();
if ( $item )
{
$player = $this->user->info( $this->user->id() );
$players = $this->user->info( $item->shop_users_id );
if ( $players->users_reg_ip === $player->users_reg_ip )
{
$this->session->set_flashdata( 'errorip', true );
}
elseif ( $player->users_money >= $item->shop_req_money && $player->users_credits >= $item->shop_req_credits)
{
$this->db->update( 'users_items', array( 'users_id' => $this->user->id(), 'users_motors_id' => '0' ), array( 'users_items_id' => $item->users_items_id ) );
$this->db->update( 'users', array( 'users_money' => $player->users_money - $item->shop_req_money, 'users_credits' => $player->users_credits - $item->shop_req_credits ), array( 'users_id' => $this->user->id() ) );
$this->db->query( 'UPDATE users SET users_money=users_money+' . $item->shop_req_money . ', users_credits=users_credits+' . $item->shop_req_credits . ' WHERE users_id=' . $this->db->escape( $item->shop_users_id ) );
$this->db->delete( 'shop', array( 'shop_id' => $item->shop_id ) );
$this->session->set_flashdata( 'success', true );
}
else
$this->session->set_flashdata( 'error', true );
}
}
header( 'Location: ' . $_SERVER['HTTP_REFERER'] );
}
It works the way it is BUT basically I am asking if thats the correct way of doing that or there should be something else I can do similiar to that but better? Would be really appreciated if there any comments on my question. Thanks in advance!