title: How to determine if first segment exists or not at CodeIgniter?
body: <p>I think I'll become a bald because of pulling my hairs...</p>
  
  <p>According to CodeIgniter tutorial and also my previous experience, I can easily determine if 2nd, 3rd or 4th segments exist or what are their values. </p>
  
  <pre><code>if($this-&gt;uri-&gt;segment(3)) {
       //do something
  }
  </code></pre>
  
  <p>or </p>
  
  <pre><code>if($this-&gt;uri-&gt;segment(3)=="foo") {
       //do something
  }
  </code></pre>
  
  <p>Everything is okay for ALL other segments except the FIRST SEGMENT!</p>
  
  <p>I can not use any conditional statements for FIRST SEGMENT! </p>
  
  <p>if($this->uri->segment(1)) does not work. Because it always returns true. But I want to check if first segment exists or NOT. When I browse to my site, because of removing index.php, it looks like www.domain.com . All other controllers goes like domain.com/firstcontroller, domain.com/secondcontroller</p>
  
  <p>BUT I need to create a condition for the WEB ROOT. </p>
  
  <p>I tried __construct() function but it didn't work neither.</p>
  
  <p>The thing I want to do is:
  I will show some HTML if current page is NOT webroot (even without 1st segment) or it's not my main controller.</p>
  
  <p>Can you help please?</p>
  
  <p>EDIT:
  Errr... I'm sorry. I've figured out the problem. It was about using correct operator. I was supposed to use XOR instead of OR. So there is no problem with determining $this->uri->segment(1) ... It's just same as other segments... </p>