Question

In my header.php file, I wrote:

 <?php require_once('includes/session.php');?>

In my admin_login.php file I wrote:

 get_header(); 
 global $session;
 $session->login($found_user);    

get_header() will include header.php which has 'session' class by
<?php require_once('includes/session.php');?>

and admin_login.php has header.php by get_header().

So why session class is not available in my admin_login.php? It show the following error:

Call to a member function is_logged_in() on a non-object in 
D:\server\htdocs\wordpress\wp-content\themes\amrajegeachi.com\super_admin_home.php on line 9

all code inside admin_login.php:

<?php 
  /*
    Template Name: admin login form
  */
?>

<?php 
require_once('includes/user.php');
get_header(); // includes.session.php has been included by header.php

?> 
      <div id="super-admin-login">              
  <?php 
if(isset($_POST['login-btn']))
{
    if(!empty($_POST['user']) || !empty($_POST['password']))
      {
          $username=$_POST['user'];
          $password=$_POST['password']; 
          $found_user = User::authenticate($username,$password);
          if($found_user){
              global $session;
               $session->login($found_user);   
          }  
      }
}
?>
  <form name="input" action="#" method="post">
    <table>
      <tr><td> Username:</td><td><input type="text" name="user" /></td> </tr>
      <tr><td> Password:</td><td><input type="password" name="password" /></td> </tr>
      <tr><td> </td><td class="btn"> <input type="submit" name="login-btn" value="Login" /></td></tr>
    </table> 
</form>
      </div>       
   <?php  
    get_footer();
    ?>
Was it helpful?

Solution

I have fixed this error.I changed getheader() to require_once("header.php"); Now it works fine

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top