Login issue that unable student to go student_home page

i got 3 type of users and currently working on student user type… at index.php where i logged as student and it should bring me to student_home.php but sadly it still stay at index.php and my browser doesnt show any error but the index.php body and footer part is blanked means gone… here my sample code…

index.php
[php]

<?php include('header.php'); //Start session session_start(); //Unset the variables stored in session unset($_SESSION['id']); ?>
<?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>&nbsp;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>&nbsp;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>&nbsp;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>&nbsp;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>&nbsp;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>&nbsp;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">&times;</button>
                <strong>Head Up!</strong>&nbsp;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>&nbsp;<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>&nbsp;Faculty

                    </div>
                    <div class="hero-unit-3">
                        <p><a href=""><i class="icon-sign-blank"></i>&nbsp;Faculty</a></p>
                        <p><a href=""><i class="icon-sign-blank"></i>&nbsp;Faculty</a></p>
                        <p><a href=""><i class="icon-sign-blank"></i>&nbsp;Faculty</a></p>
                        <p><a href=""><i class="icon-sign-blank"></i>&nbsp;Faculty</a></p>
                    </div>
                </div>
            </div>
        </div>
    </div>



    <br>
    <div class="alert alert-success"><i class="icon-file icon-large"></i>&nbsp;<strong>Project</strong></div>
    <div class="hero-unit-2">
     Project
    </div>

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

navhead.php
[php]

    <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 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>&nbsp;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>&nbsp;Student</a></li>
                                        <li><a href="#teacher" role="button"  data-toggle="modal"><i class="icon-user-md icon-large"></i>&nbsp;Teacher</a></li>

                                    </ul>
                                </div>

                                <!-- end login -->
                                <?php include('student_modal.php'); ?>
                                <?php include('teacher_modal.php'); ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>


    </div>

[/php]

student_modal.php

[php]

</div>
<div class="modal-body">

    <div class="alert alert-info">
        <button type="button" class="close" data-dismiss="alert">&times;</button>
        <strong>Login Student!</strong>&nbsp;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>&nbsp;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>&nbsp;Close</button>

</div>

login_student.php

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

<?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>&nbsp;Teacher</a><span class="divider">/</span></li>
                <li  class="active"><i class="icon-group icon-large"></i>&nbsp;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">&times;</button>
                <strong>Login Student!</strong>&nbsp;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>&nbsp;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">&times;</button>
                            <div class="alert alert-danger"><i class="icon-remove-sign"></i>&nbsp;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>&nbsp;Home</a></li>
                    <li><a href="#"><i class="icon-file-alt icon-large"></i>&nbsp;New And Events</a></li>
                    <li><a href="#"><i class="icon-sitemap icon-large"></i>&nbsp;Site Map</a></li>
                    <li><a href="#"><i class="icon-envelope-alt icon-large"></i>&nbsp;Contact Us</a></li>
                    <li class="nav-header">About US</li>
                    <li><a href="#"><i class="icon-book icon-large"></i>&nbsp;Mission</a></li>
                    <li><a href="#"><i class="icon-book icon-large"></i>&nbsp;Vision</a></li>
                    <li><a href="#"><i class="icon-list-alt icon-large"></i>&nbsp;History</a></li>

                </ul>
            </div>

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

[/php]
[/php]

Well, first, I am not 100% sure on this, but, if you are using the line:
session_regenerate_id();
To create a new session ID, I think you need the argument true in it.
session_regenerate_id(true);

Also, I think you need a SPACE inside your header command, so this line:
header(‘location:student_home.php’);
Should be:
header(‘location: student_home.php’);
Minor change, but, I had that issue on one of my sites.

Lastly, the redirection code you have:
header(‘location: student_home.php’);
session_write_close();
exit();
Is totally incorrect. Once a “header” command is executed, there is nothing after it.
The page will switch to the new page and no further code is needed after it.
Therefore, remove the other two lines. If you feel you need to close the session or if you use frames and what to use multiple sessions (since only one session runs at a time), you can still do the session-write-close, but, do it BEFORE you switch pages as that command does not get executed.

Hope that helps… Good luck !

I will try based on what u say… hmm do the session-write-close() before it change page? it mean put that code before the header(location: student_home.php)?

i already working on it… but it still the same… nth much… still cannt bring student to student_home.php page…

Well, first, if you recreate your session with the regenerate command, you are making a
totally new session. Therefore, any session variables will be gone. You will have to reload
them before redirecting. I just noted that. Also, that regenerate command only works on PHP 5.1
or higher. Which version of PHP are you using on your server? You can figure that out by using
this command near the top of your PHP code: phpinfo(); this will display all of your PHP setup
options adn the version is near the top of the page…

So, next, repost your current versions so we can peek at it. I think you are close to solving this one.

Sponsor our Newsletter | Privacy Policy | Terms of Service