Joemar Alfeche
Joemar Alfeche

Reputation: 15

Call to undefined function logged_in()

I have a function logged_in() whose purpose is to check if the user is logged in. This function, located inside users.php, is called from login.php.

Everytime I attempt to call this function I get the following error

Call to undefined function logged_in() in line 67

Here's my code

users.php

function logged_in() //line 67 
{
    return (isset($_SESSION['user_id'])) ? true : false;
}

login.php

if(logged_in()===true)
{
    include 'includes/widgets/loggedin.php';
}
else{
    include 'includes/widgets/login.php';
}

What seems to be the issue?

Upvotes: 0

Views: 1824

Answers (3)

Ronald Swets
Ronald Swets

Reputation: 1667

don't forget to include or require the users.php file

Upvotes: 2

John Conde
John Conde

Reputation: 219804

Looks like you forgot to include users.php. If you don't include that file you don't have access to any functions declared within it.:

<?php 
include('users.php');
if(logged_in()===true)
{
    include 'includes/widgets/loggedin.php';
}
else{
        include 'includes/widgets/login.php';
}

?>

Upvotes: 2

aynber
aynber

Reputation: 23001

Make sure that users.php is included into login.php. Otherwise, it won't know that the function is there.

<?php 

include_once('users.php');
if(logged_in()===true)
{
    include 'includes/widgets/loggedin.php';
}
else{
        include 'includes/widgets/login.php';
}

?>

Upvotes: 3

Related Questions