Welcome Guest, Not a member yet? Register   Sign In
is_int issue?
#1

[eluser]Unknown[/eluser]
I have code:
Code:
else if($action == 'edit')
            {
                $gallery_id = $this->uri->segment(5, FALSE);
                
                if(!is_int($gallery_id) || $gallery_id == FALSE)
                    show_404();
                
            }
No matter if $gallery_id is int or not it is showing me show_404 :/
Code:
else if($action == 'edit')
            {
                $gallery_id = $this->uri->segment(5, FALSE);
                
                if(!is_int($gallery_id))
                    show_404();
                
            }
It also show 404 no matter if $gallery_id is int or not...
#2

[eluser]CroNiX[/eluser]
$this->uri->segment() returns a string, or boolean FALSE if the segment doesn't exist. So, it will never be an int unless you cast it like $gallery_id = (int)$gallery_id; If you do that though, it will never be boolean FALSE, it will be 0 in that case.
Code:
else if($action == 'edit')
{
  $gallery_id = $this->uri->segment(5, FALSE);
  
  //if the segment exists, cast it as an int or else trigger 404
  if ($gallery_id !== FALSE)
  {
    $gallery_id = (int)$gallery_id;
  }
  else
  {
    show_404();
  }              
}
You can check for yourself by running var_dump($gallery_id); right after you get it from the segment before doing anything else.




Theme © iAndrew 2016 - Forum software by © MyBB