title: PHP, URI routing, switch statement and headers
body: <p>I am trying to get a PHP URI routing system to work.</p>
  
  <p>I am getting the following error when the <code>$page_url = 'services';</code> line is commented.</p>
  
  <pre><code>PHP Warning:  Cannot modify header information - headers already sent by (output started at PATH:12) in PATH on line 22
  </code></pre>
  
  <p>Line 12 is the var_dump and line 22 is the 404 headers.</p>
  
  <p>If I uncomment the <code>$page_url = 'services';</code> I don't get an error.</p>
  
  <p>Commented or uncommented, the var_dump outputs the same thing : string(8) "services".</p>
  
  <p>The page I'm loading is <a href="http://testwebsite.com/fr/services" rel="nofollow">http://testwebsite.com/fr/services</a></p>
  
  <p>Here is the <code>index.php</code> code.</p>
  
  <pre><code>&lt;?php
  
  // get requested uri
  $uri = explode('/', strtolower(substr($_SERVER['REQUEST_URI'], 1)));
  
  //set variables
  $lang = $uri[0];
  $page_url = $uri[1];
  
  //debug
  $page_url = 'services';
  var_dump($page_url);
  
  // route current page
  switch($page_url){
  
      case 'services':
          $page_id = 'services';
          break;
  
      default:
          header("HTTP/1.0 404 Not Found");
          break;
  }
  
  ?&gt;
  </code></pre>
  
  <p>Here is the <code>.htaccess</code> file.</p>
  
  <pre><code>RewriteEngine On
  RewriteCond %{REQUEST_URI} !=/index.php
  RewriteRule .* /index.php
  
  AddDefaultCharset UTF-8
  
  IndexIgnore *
  Options -Indexes
  </code></pre>
  
  <p>I don't understand why it tries to run the default case when the $page_url variable is determined through parsing of the requested URI but doesn't if it's set manually since in both case the var_dump outputs the exact same thing.</p>
  
  <p>Furthermore, if I add <code>echo'default';</code> to the default case, it doesn't output it but I still get a warning in the log. It makes no sense to me.</p>
  
  <p>Thanks for your help.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>It should be noted that if I add <code>echo'services';</code> to the services case, it gets outputted. I still get a warning on the header though. As if the <code>break;</code> isn't registering. But it is since it doesn't echo "default" either.</p>