title: create a simple PHP login / logout system
body: <p>This is for an assignment, however ive done a lot on my part to research but i feel like ive reached a wall. I need to create a page where the user can go to sign in (login.php), once they're signed in they're redirected to the index page. The link they clicked to login should be replaced with a logout link. </p>
  
  <p>however with all this noted, first things first i do get into the session part and ive echoed the variables and retrieved them however it doesnt do the redirect to the index.php also when i manually click to the index.php after logging the session variables are empty. what am i doing wrong here??? </p>
  
  <p>so this is my php code in the login.php</p>
  
  <pre><code>          $found = false;
            //read the read.txt until the end of file
            while(!feof($inputFile) &amp;&amp; $found == false)  
            {
  
              $line = fgets($inputFile);  
              // replace the special charater within the lines by there proper entity code
              $lineArray = preg_split("/\,/", (string)$line);
  
              if(strcmp($_REQUEST['email'],$lineArray[2])  &amp;&amp; strcmp($_REQUEST['pwd'],$lineArray[4]))
              {
                          $found = true;
                          echo "&lt;script&gt;alert(' FOUND!')&lt;/script&gt;";
                          session_start();
                          $myuseremail=$_REQUEST['email'];
                          $mypassword= $_REQUEST['pwd'];
  
                          $_SESSION['login_email']=$myuseremail;
                          $_SESSION['login_pwd']=$mypassword;
                          setcookie("login_email", $_SESSION['login_email'], time()+60*60*24);
                          setcookie("login_pwd", $_SESSION['login_pwd'], time()+60*60*24);
                          header('Location:index.php');
              }
            }
            fclose($inputFile);
  </code></pre>
  
  <p>and then in my index.php i contain this code before the body of my html </p>
  
  <pre><code>    &lt;?php
  
        session_start();
     if(isset($_SESSION['login_email']) &amp;&amp; isset($_SESSION['login_pwd']))
     {
      $user_check=true;
      echo $_SESSION['login_email'];
     }
     else
     {
      $user_check=false; 
     }
  
  ?&gt;
  </code></pre>
  
  <p>within the index.php i also have this code lined in for my links </p>
  
  <pre><code>     &lt;li&gt;&lt;a href="index.php"&gt;Home&lt;/a&gt;&lt;/li&gt;
   &lt;li&gt;&lt;a href="register.php"&gt;Register&lt;/a&gt;&lt;/li&gt;
  
   &lt;?php
  
  if ($user_check){
                   print "&lt;li&gt;&lt;a href='logout.php'&gt;Logout&lt;/a&gt;&lt;/li&gt;";
   }
   else{
   print "&lt;li&gt;&lt;a href='login.php'&gt;Login&lt;/a&gt;&lt;/li&gt;";
   }
   ?&gt;
              &lt;li&gt;&lt;a href="#"&gt; Link 4&lt;/a&gt;&lt;/li&gt;
  </code></pre>