title: How to redirect a file using function
body: <p>I'm trying to access my file where it contains a home page using a function from another file <code>(redirect.php)</code>. <code>MyWebsite/main/main.html</code> this is the location of my file that I want to access. I stuck in here <code>redirect::toMain('main.html');</code> don't have a idea how to link the full path so I will be directing to the home page. I tried to pass <code>('main.html')</code> value to the function <code>toMain()</code> but it didn't work. Location of folder below.</p>
  
  <p><a href="https://i.stack.imgur.com/lhImo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lhImo.png" alt="Screenshot"></a></p>
  
  <p>So MyWebsite is the main folder and it contains sub-folder listed below.</p>
  
  <ul>
  <li>function (folder) contains a redirect function</li>
  <li>main (folder) contains a html. <code>main.html</code> where it set as my home page. This is where the user will redirect.</li>
  </ul>
  
  <p><strong>Class: <em>redirect.php</em></strong> Location: MyWebsite/function/redirect.php</p>
  
  <pre><code>&lt;?php
  
  class redirect
  {
  public static function toMain($location = null)
  {
      if($location)
      {
          header('Location: ' . $location);
          exit();
      }
  }
  }
  $a = new redirect();
  ?&gt;
  </code></pre>
  
  <p><strong>loginProcess.php</strong></p>
  
  <pre><code>&lt;?php
  
  session_start();
  
  require_once('../connection/connection.php');
  require_once('../connection/loginCRUD.php');
  require_once('../function/redirect.php');
  
  if(isset($_POST['submit']))
  {
  $dbusername = $_POST['loginUsername']; //Store value of textfield in array
  $dbpassword = $_POST['loginPassword'];
  
  if(!empty($dbusername) &amp;&amp; !empty($dbpassword))
  {
      if((new loginCRUD)-&gt;readLogin($dbusername,$dbpassword)) //If true
      {
         // echo "You are logged in!";
          $_SESSION['loginUsername'] = $dbusername;//Session are stored in array.
  
          // redirect the user to the home page
          redirect::toMain('main.html');
      }
      else
      {
          echo "Incorrect username and/or password";
      }
  }
  
  }//end of isset
  ?&gt;
  </code></pre>