2 Replies - 1384 Views - Last Post: 08 October 2012 - 05:41 PM Rate Topic: -----

#1 Bestford  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 05-December 11

error with login page

Posted 08 October 2012 - 04:50 PM

hey guys, im following a tutorial online(phpacademy) and I've hit an error and I seem to not being able to solve it can you help? please and thanks in advanced

The filing structure on this is rather complicated


error is: Fatal error: Call to undefined function logged_in() in C:\xampp\htdocs\lr\includes\aside.php on line 3


aside.php
<aside>
	<?php
	if (logged_in() === TRUE ) {
		echo 'Logged in';
	} else {
		include 'includes/widgets/login.php';
	}
	?>
</aside>



users.php
<?php

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


function user_exists($username){
	$username = sanitize($username);
	return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username'"), 0) == 1) ? true :false;
}

function user_active($username){
	$username = sanitize($username);
	return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username' AND `active` = 1"), 0) == 1) ? true :false;
}

function user_id_from_username($username){
	$username = sanitize($username);
	return mysql_result(mysql_query("SELECT `user_id` FROM `users` WHERE `username` = '$username' "), 0, 'user_id');
}


function login($username, $password){
	$user_id = user_id_from_username($username);
	
	$username = sanitize($username);
	$password = md5($password);
	
	return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username' AND `password` = '$password'"), 0)== 1) ? $user_id : false;
}

?>


This post has been edited by Bestford: 08 October 2012 - 04:51 PM


Is This A Good Question/Topic? 0
  • +

Replies To: error with login page

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 6,017
  • Joined: 08-June 10

Re: error with login page

Posted 08 October 2012 - 05:40 PM

Hey.

Where is the "users.php" file included into the "aside.php" file?

The error is telling you that the "logged_in()" function doesn't exist, so somehow it the "users.php" file must not be included correctly.

You can try to simply include the file right before that if statement. I'd recommend using require_once to do that. That way the file won't be loaded multiple times if it is included somewhere else as well.

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


The ternary operator is unnecessary there. The isset() function already returns a boolean, so you can simply return that.

The above is exactly the same as doing:
return isset($_SESSION['user_id']);


Was This Post Helpful? 0
  • +
  • -

#3 Bestford  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 05-December 11

Re: error with login page

Posted 08 October 2012 - 05:41 PM

resolved
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1