2

I want to count total number of segments in codeigniter so I can display error if user/visitor enter additional segment in my url.

Muhammad Asfund
  • 97
  • 2
  • 10

1 Answers1

7

Have you checked the manual yet? There is such method that will get the total segments. $this->uri->total_segments()

Or also you can use $this->uri->segment_array().

$total = count($this->uri->segment_array());
user1978142
  • 7,946
  • 3
  • 17
  • 20