PHP problem - undefined function

+2 Jad Samadi · August 28, 2014
Thank you for the help on the previous post, i got stuck now again so please i would appreciate your help again

first let me tell you what is happening ... on an aside div i was trying to make the login form .. now what i wanted to do is that on an aside division i would echo/put the form for the login if the user isn't logged in and that when he log in on the aside division it echo:logged in and won't show the form any more (logical) so iv started to code :

now this is the code for the aside division : 

        <aside>

        <?php

        if (logged_in() === true) {
             echo 'Logged in';

        }else {

          include 'includes/widgets/login.php';


        }

        ?>

        </aside>

and this is the code for the function : 

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

now of course ill be trying to test it and when i refreshed my index.php page it showed me an error on the aside division that say : Fatal error: Call to undefined function logged_in() in C:\xampp\htdocs\lr\includes\asside.php on line 6

please help for i do not know why this is happening ... i defined the function logged_in
() and yet i have no idea why it wont work .
thanks for reading .

Post a Reply

Replies

Oldest  Newest  Rating
0 Jad Samadi · August 29, 2014
for some reason both of the solutions didn't really work ... so please help me .. here all the info :

aside:

        <aside>

        <?php

       if (logged_in() === true)   {

         } else {

include 'includes/widgets/login.php';

        }


?>
        </aside>


users:

<?php

function logged_in() {

    return (isset($_SESSION['user_id'])) ? true : false;

}

//with more codes here

?>

the index page won't even show the footer now for some reason and on the aside division it give this error :



Fatal error: Call to undefined function logged_in() in C:\xampp\htdocs\lr\includes\asside.php on line 5
0 Jad Samadi · August 29, 2014
ok sorry didn't really understand that :/
+1 JOhaL jaTT · August 29, 2014
Again you did the same mistake "{"
<?php

if ($logged_in === true) {
echo 'Loged in'
} else {
include 'includes/widgets/login.php';
}
?>

</aside>
$logged_in = logged_in();{                  //-------------------Here ---------------------
return (isset($_SESSION['user_id'])) ? true: false;
}
0 Jad Samadi · August 29, 2014
thanks for your help ... now iv followed your instructions and ended up with this : 

        <aside>

        <?php

if ($logged_in === true) {
   echo 'Loged in'
} else {
include 'includes/widgets/login.php';
}
?>

        </aside>

$logged_in = logged_in();
 return (isset($_SESSION['user_id'])) ? true: false;
}

error :


Parse error: syntax error, unexpected '}', expecting ',' or ';' in C:\xampp\htdocs\lr\includes\asside.php on line 8

can you help me with this?
0 JOhaL jaTT · August 29, 2014
try to use this then you will know problem 
if (logged_in() == false) {
echo 'Logged in';

}else {

include 'includes/widgets/login.php';


}

?> 
then tell us what did you get.
+1 Franz Schmidt · August 28, 2014
Could you please post the exact order of your codelines ?:ermm:
  • 1

PHP

107,187 followers
About

Server-side, HTML embedded scripting language used to create dynamic Web pages.

Links
Moderators