Jump to content

Student login issue


aquilina

Recommended Posts

I have a problem with login issue that when i loggin as student from index.php it should bring me to student_home php.. but it doesnt show anything and just bring me to index.php back.. i mixed up about header and session part..

 

index.php

	   
   <?php
   include('header.php');
   //Start session
   session_start();
   //Unset the variables stored in session
   unset($_SESSION['id']);
   ?>
   <body>
  
      <?php include('navhead.php'); ?>
  
      <div class="container">
          <div class="row-fluid">
              <div class="span3">
  
                  <div class="hero-unit-3">
                      <div class="alert-index alert-success">
                          <i class="icon-calendar icon-large"></i>
                          <?php
                          $Today = date('y:m:d');
                          $new = date('l, F d, Y', strtotime($Today));
                          echo $new;
                          ?>
                      </div>
                  </div>
  
                  <div class="hero-unit-1">
                      <ul class="nav  nav-pills nav-stacked">
  
  
                          <li class="nav-header">Links</li>
                          <li class="active"><a href="#"><i class="icon-home icon-large"></i> Home
                                  <div class="pull-right">
                                      <i class="icon-double-angle-right icon-large"></i>
                                  </div> 
                              </a></li>
  
                          <li><a href="sitemap.php"><i class="icon-sitemap icon-large"></i> Site Map
                                  <div class="pull-right">
                                      <i class="icon-double-angle-right icon-large"></i>
                                  </div> 
                              </a></li>
                          <li><a href="contact.php"><i class="icon-envelope-alt icon-large"></i> Contact Us
                                  <div class="pull-right">
                                      <i class="icon-double-angle-right icon-large"></i>
                                  </div> 
                              </a>                
                          </li>
                          <li class="nav-header">About US</li>
                          <li><a  href="#mission" role="button" data-toggle="modal"><i class="icon-book icon-large"></i> Mission
                                  <div class="pull-right">
                                      <i class="icon-double-angle-right icon-large"></i>
                                  </div> 
                              </a></li>
                          <li><a href="#vision" role="button" data-toggle="modal"><i class="icon-book icon-large"></i> Vision
                                  <div class="pull-right">
                                      <i class="icon-double-angle-right icon-large"></i>
                                  </div> 
                              </a></li>
                          <li><a href="history.php"><i class="icon-list-alt icon-large"></i> History
                                  <div class="pull-right">
                                      <i class="icon-double-angle-right icon-large"></i>
                                  </div> 
                              </a></li>
  
                      </ul>
                  </div>
                  <br>
  
  
              </div>
              <div class="span9">
                  <section class="main">
                      <div class="custom-calendar-wrap">
                          <div id="custom-inner" class="custom-inner">
                              <div class="custom-header clearfix">
                                  <nav>
                                      <span id="custom-prev" class="custom-prev"></span>
                                      <span id="custom-next" class="custom-next"></span>
                                  </nav>
                                  <h2 id="custom-month" class="custom-month"></h2>
                                  <h3 id="custom-year" class="custom-year"></h3>
                              </div>
                              <div id="calendar" class="fc-calendar-container"></div>
                          </div>
                      </div>
                  </section>
  
  
                  <div class="alert alert-info">
                      <button type="button" class="close" data-dismiss="alert">×</button>
                      <strong>Head Up!</strong> Welcome to Morpheus.
                  </div>
                  <div class="slider-wrapper theme-default">
                  <?php include('slider.php'); ?>
                  </div>
                  <!-- end slider -->
              </div>
 
         </div>
 
     </div>
     <!---------------->
     <div class="container">
 
         <div class="row-fluid">
             <div class="span12">
 
                 <div class="row-fluid">
                     <div class="span9">
                         <div class="alert alert-success"><i class="icon-file icon-large"></i> <strong>Mission</strong></div>
                         <div class="hero-unit-2">
                             Announcements
                             
                         </div>
 
                     </div>
                     <div class="span3">
                         <div class="alert alert-info">
                             <i class="icon-building icon-large"></i> Faculty
 
                         </div>
                         <div class="hero-unit-3">
                             <p><a href=""><i class="icon-sign-blank"></i> Faculty</a></p>
                             <p><a href=""><i class="icon-sign-blank"></i> Faculty</a></p>
                             <p><a href=""><i class="icon-sign-blank"></i> Faculty</a></p>
                             <p><a href=""><i class="icon-sign-blank"></i> Faculty</a></p>
                         </div>
                     </div>
                 </div>
             </div>
         </div>
 
 
 
         <br>
         <div class="alert alert-success"><i class="icon-file icon-large"></i> <strong>Project</strong></div>
         <div class="hero-unit-2">
          Project
         </div>
 
         <?php include('footer.php'); ?>
     </div>
 
 </body>
 </html>
 

navhead.php


		  
  <div class="row-fluid">
      <div class="span12">
          
          <div class="navbar navbar-fixed-top navbar-inverse">
              <div class="navbar-inner">
                  <div class="container">
                      
                      <a class="btn btn-navbar" data-toggle="collapse" data-targer=".nav-collapse">
                         <span class="icon-bar"></span>
                         <span class="icon-bar"></span>
                         <span class="icon-bar"></span>
                     </a>
                     
                     
                     <div class="nav-collapse collapse">
                         
                         <i class="icon-facebook-sign icon-large" id="color_white"></i>
                         <i class="icon-twitter icon-large" id="color_white"></i>
                         <i class="icon-google-plus icon-large" id="color_white"></i>
                         <i class="icon-github-alt icon-large" id="color_white"></i>
                         <i class="icon-linkedin-sign icon-large" id="color_white"></i>
                         <div class="pull-right">
                             <form class="navbar-search pull-left">
                                 <i class="icon-search icon-large" id="color_white"></i>
                                 <input type="text" class="search-query" placeholder="Search">
                                     
                             </form>
                         </div>
                     </div>        
                     
                     
               
                 </div>
             </div>
             
         </div>
         
     </div>
     
     
 </div>
         <div class="hero-unit-header">
             <div class="container">
 
                 <div class="row-fluid">
                     <div class="span12">
                         <div class="row-fluid">
                             <div class="span6">
                                 <img src="admin/images/head.png">
                             </div>
                             <div class="span6">
                                 <div class="pull-right">
                                     <!--- login button -->

                                     <div class="btn-group">
                                         <button class="btn btn-success"><i class="icon-signin icon-large"></i> Login</button>
                                         <button class="btn dropdown-toggle" data-toggle="dropdown">
                                             <span class="caret"></span>
                                         </button>
                                         <ul class="dropdown-menu">
                                             <li><a href="#student" role="button"  data-toggle="modal"><i class="icon-user icon-large"></i> Student</a></li>
                                             <li><a href="#teacher" role="button"  data-toggle="modal"><i class="icon-user-md icon-large"></i> Teacher</a></li>
 
                                         </ul>
                                     </div>
 
                                     <!-- end login -->
                                     <?php include('student_modal.php'); ?>
                                     <?php include('teacher_modal.php'); ?>
                                 </div>
                             </div>
                         </div>
                     </div>
                 </div>
 
             </div>
 
 
         </div>
 

student_modal.php


   <div id="student" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
       <div class="modal-header">
   
       </div>
       <div class="modal-body">
   
           <div class="alert alert-info">
              <button type="button" class="close" data-dismiss="alert">×</button>
              <strong>Login Student!</strong> Please Enter the Details Below.
          </div>
          <form class="form-horizontal" method="post">
              <div class="control-group">
                  <label class="control-label" for="inputEmail">Username</label>
                  <div class="controls">
                      <input type="text" name="username" id="inputEmail" placeholder="Username">
                  </div>
              </div>
              <div class="control-group">
                  <label class="control-label" for="inputPassword">Password</label>
                  <div class="controls">
                      <input type="password" name="password" id="inputPassword" placeholder="Password">
                  </div>
              </div>
  
  
              <div class="control-group">
                  <div class="controls">
                      <button type="submit" name="login" class="btn btn-info"><i class="icon-signin icon-large"></i> Sign in</button>
                  </div>
  
  
              </div>
  
              <?php
              if (isset($_POST['login'])) {
  
                  function clean($str) {
                      $str = @trim($str);
                      if (get_magic_quotes_gpc()) {
                          $str = stripslashes($str);
                      }
                      return mysql_real_escape_string($str);
                  }
  
                  $username = clean($_POST['username']);
                  $password = clean($_POST['password']);
  
                  $query = mysql_query("select * from student where username='$username' and password='$password'") or die(mysql_error());
                  $count = mysql_num_rows($query);
                  $row = mysql_fetch_array($query);
  
  
                  if ($count > 0) {
                      session_start();
                      session_regenerate_id();
                      $_SESSION['id'] = $row['student_id'];
                      header('location:student_home.php');
                      session_write_close();
                      exit();
                  } else {
                      header('error_login.php');
                    
                      ?>
  
                      <?php
                  }
              }
              ?>
  
          </form>
  
  
          <!-- teacher -->
  
  
  
  
      </div>
      <div class="modal-footer">
          <button class="btn" data-dismiss="modal" aria-hidden="true"><i class="icon-remove-sign icon-large"></i> Close</button>
  
      </div>
  </div>
  
  login_student.php
  
  [php]<?php
  include('header.php');
  //Start session
  session_start();
  //Unset the variables stored in session
  unset($_SESSION['id']);
  ?>
  <body>
  
      <?php include('navhead.php'); ?>
  
     <div class="container">
         <div class="row-fluid">
             <div class="span10">
                 <ul class="breadcrumb">
                     <li class="active">Login<span class="divider">/</span></li>
                     <li><a href="login_student.php"><i class="icon-group icon-large"></i> Teacher</a><span class="divider">/</span></li>
                     <li  class="active"><i class="icon-group icon-large"></i> Student</li>
 
                     <div class="pull-right">       
                         <li>   
                             <i class="icon-calendar icon-large"></i>
                             <?php
                             $Today = date('y:m:d');
                             $new = date('l, F d, Y', strtotime($Today));
                             echo $new;
                             ?>
                         </li>
                     </div>  
                 </ul>
 
                 <div class="alert alert-info">
                     <button type="button" class="close" data-dismiss="alert">×</button>
                     <strong>Login Student!</strong> Please Enter the Details Below.
                 </div>
 
                 <form class="form-horizontal" method="post">
                     <div class="control-group">
                         <label class="control-label" for="inputEmail">Username</label>
                         <div class="controls">
                             <input type="text" name="username" id="inputEmail" placeholder="Username">
                         </div>
                     </div>
                     <div class="control-group">
                         <label class="control-label" for="inputPassword">Password</label>
                         <div class="controls">
                             <input type="password" name="password" id="inputPassword" placeholder="Password">
                         </div>
                     </div>
 
 
                     <div class="control-group">
                         <div class="controls">
                             <button type="submit" name="login" class="btn btn-info"><i class="icon-signin"></i> Sign in</button>
                         </div>
 
 
                     </div>
 
                     <?php
                    
                     if (isset($_POST['login'])) {
 
                         function clean($str) {
                             $str = @trim($str);
                             if (get_magic_quotes_gpc()) {
                                 $str = stripslashes($str);
                             }
                             return mysql_real_escape_string($str);
                         }
 
                         $username = clean($_POST['username']);
                         $password = clean($_POST['password']);
 
                         $query = mysql_query("select * from user where username='$username' and password='$password'") or die(mysql_error());
                         $count = mysql_num_rows($query);
                         $row = mysql_fetch_array($query);
 
 
                         if ($count > 0) {
                             session_start();
                             session_regenerate_id();
                             $_SESSION['id'] = $row['user_id'];
                             header('location:student_home.php');
                             session_write_close();
                             exit();
                         } else {
                             session_write_close();
                             ?>
                             <div class="pull-right">   
                                 <button type="button" class="close" data-dismiss="alert">×</button>
                                 <div class="alert alert-danger"><i class="icon-remove-sign"></i> Access Denied</div>
                             </div>
                             <?php
                             exit();
                         }
                     }
                     ?>
 
                 </form>
 
 
 
 
             </div>
             <div class="span2">
 
                 <div class="hero-unit-1">
                     <ul class="nav  nav-pills nav-stacked">
                         <li class="nav-header">Links</li>
                         <li><a href="index.php"><i class="icon-home icon-large"></i> Home</a></li>
                         <li><a href="#"><i class="icon-file-alt icon-large"></i> New And Events</a></li>
                         <li><a href="#"><i class="icon-sitemap icon-large"></i> Site Map</a></li>
                         <li><a href="#"><i class="icon-envelope-alt icon-large"></i> Contact Us</a></li>
                         <li class="nav-header">About US</li>
                         <li><a href="#"><i class="icon-book icon-large"></i> Mission</a></li>
                         <li><a href="#"><i class="icon-book icon-large"></i> Vision</a></li>
                         <li><a href="#"><i class="icon-list-alt icon-large"></i> History</a></li>
 
                     </ul>
                 </div>
 
             </div>
         </div>
         <?php include('footer.php'); ?>
     </div>
 
 
 
 
 
 
 </body>
 </html>
 
 
 

login_student.php

    <?php
include('header.php');
//Start session
session_start();
//Unset the variables stored in session
unset($_SESSION['id']);
?>
<body>

    <?php include('navhead.php'); ?>

    <div class="container">
        <div class="row-fluid">
            <div class="span10">
                <ul class="breadcrumb">
                    <li class="active">Login<span class="divider">/</span></li>
                    <li><a href="login_student.php"><i class="icon-group icon-large"></i> Teacher</a><span class="divider">/</span></li>
                    <li  class="active"><i class="icon-group icon-large"></i> Student</li>

                    <div class="pull-right">       
                        <li>   
                            <i class="icon-calendar icon-large"></i>
                            <?php
                            $Today = date('y:m:d');
                            $new = date('l, F d, Y', strtotime($Today));
                            echo $new;
                            ?>
                        </li>
                    </div>  
                </ul>

                <div class="alert alert-info">
                    <button type="button" class="close" data-dismiss="alert">×</button>
                    <strong>Login Student!</strong> Please Enter the Details Below.
                </div>

                <form class="form-horizontal" method="post">
                    <div class="control-group">
                        <label class="control-label" for="inputEmail">Username</label>
                        <div class="controls">
                            <input type="text" name="username" id="inputEmail" placeholder="Username">
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="inputPassword">Password</label>
                        <div class="controls">
                            <input type="password" name="password" id="inputPassword" placeholder="Password">
                        </div>
                    </div>


                    <div class="control-group">
                        <div class="controls">
                            <button type="submit" name="login" class="btn btn-info"><i class="icon-signin"></i> Sign in</button>
                        </div>


                    </div>

                    <?php
                   
                    if (isset($_POST['login'])) {

                        function clean($str) {
                            $str = @trim($str);
                            if (get_magic_quotes_gpc()) {
                                $str = stripslashes($str);
                            }
                            return mysql_real_escape_string($str);
                        }

                        $username = clean($_POST['username']);
                        $password = clean($_POST['password']);

                        $query = mysql_query("select * from user where username='$username' and password='$password'") or die(mysql_error());
                        $count = mysql_num_rows($query);
                        $row = mysql_fetch_array($query);


                        if ($count > 0) {
                            session_start();
                            session_regenerate_id();
                            $_SESSION['id'] = $row['user_id'];
                            header('location:student_home.php');
                            session_write_close();
                            exit();
                        } else {
                            session_write_close();
                            ?>
                            <div class="pull-right">   
                                <button type="button" class="close" data-dismiss="alert">×</button>
                                <div class="alert alert-danger"><i class="icon-remove-sign"></i> Access Denied</div>
                            </div>
                            <?php
                            exit();
                        }
                    }
                    ?>

                </form>




            </div>
            <div class="span2">

                <div class="hero-unit-1">
                    <ul class="nav  nav-pills nav-stacked">
                        <li class="nav-header">Links</li>
                        <li><a href="index.php"><i class="icon-home icon-large"></i> Home</a></li>
                        <li><a href="#"><i class="icon-file-alt icon-large"></i> New And Events</a></li>
                        <li><a href="#"><i class="icon-sitemap icon-large"></i> Site Map</a></li>
                        <li><a href="#"><i class="icon-envelope-alt icon-large"></i> Contact Us</a></li>
                        <li class="nav-header">About US</li>
                        <li><a href="#"><i class="icon-book icon-large"></i> Mission</a></li>
                        <li><a href="#"><i class="icon-book icon-large"></i> Vision</a></li>
                        <li><a href="#"><i class="icon-list-alt icon-large"></i> History</a></li>

                    </ul>
                </div>

            </div>
        </div>
        <?php include('footer.php'); ?>
    </div>






</body>
</html>



    
Link to comment
Share on other sites

in case the OP revisits this thread, you cannot use a header() statement, or a session_start() or session_regenerate_id(); statement after you have output anything to the browser.

 

the solution to this it to organize the php code on your page so that the 'business logic' (determines what to do on the page and gets the data the page needs) comes first and the the 'presentation logic' (deals only with the production of the html/css/javascript output) comes last.

 

you also need to set php's error_reporting to E_ALL and display_errors to ON in your php.ini on your development system so that php will help you by reporting and displaying all the errors it detects. your header() statement would be producing php errors since it comes after you have output a bunch of html on the page.

Link to comment
Share on other sites

in case the OP revisits this thread, you cannot use a header() statement, or a session_start() or session_regenerate_id(); statement after you have output anything to the browser.

 

the solution to this it to organize the php code on your page so that the 'business logic' (determines what to do on the page and gets the data the page needs) comes first and the the 'presentation logic' (deals only with the production of the html/css/javascript output) comes last.

 

you also need to set php's error_reporting to E_ALL and display_errors to ON in your php.ini on your development system so that php will help you by reporting and displaying all the errors it detects. your header() statement would be producing php errors since it comes after you have output a bunch of html on the page.

deafult xampp php.ini the display_error = on i checked already.. but i run my code in dreamweaver, sometime in netbean... and also zend studio.. :shrug:

Link to comment
Share on other sites

Did you check the errors in the PHP log files?

Did you try to debug the HTTP headers you get? If you don't know how, check out this page : https://developer.chrome.com/devtools/index

In chrome, just check the Network tab of the developer tools, click on the filter icon and choose "documents". When you load your page, your should see your "Location: ..." in the "headers" tab. If not, it didn't get there somehow.

 

If you're not sure about php.ini, you can add this line to your code:

ini_set('error_reporting', E_ALL);

Just be sure to remove it when you put your code online.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.