Private Messaging System. [Fixed]

Post here is you are having problems with any of the tutorials.
Post Reply
Z645
Posts: 33
Joined: Thu Jul 26, 2012 5:08 pm

Private Messaging System. [Fixed]

Post by Z645 »

I'm getting an error of: Fatal error: Call to undefined function validate_credentials() in /home/a2954500/public_html/messages/core/init.inc.php on line 18 When I login.


init.inc.php
[syntax=php]<?php

$core_path = dirname(__FILE__);

if (empty($_GET['page']) || in_array("{$_GET['page']}.page.inc.php", scandir("{$core_path}/pages")) == false){
header('HTTP/1.1 404 Not Found');
header('Location: index.php?page=inbox');

die();
}

session_start();

mysql_connect('mysql12.000webhost.com', '*Hidden*', '*Hidden*');
mysql_select_db('a2954500_users');

if (isset($_POST['user_name'], $_POST['user_password'])){
if (($user_id = validate_credentials($_POST['user_name'], $_POST['user_password'])) !== false){
$_SESSION['user_id'] = $user_id;
header('Location: index.php?page=inbox');
die();
}
}

if (empty($_SESSION['user_id']) && $_GET['page'] !== 'login'){
header('HTTP/1.1 403 Forbidden');
header('location: index.php?page=login');

die();
}

$include_file = "{$core_path}/pages/{$_GET['page']}.page.inc.php";
?>[/syntax]

user.inc.php
[syntax=php]<?php

// checks a given username and password combination, returning the user's ID.
function validate_credentials($user_name, $user_password){
$user_name = mysql_real_escape_string($user_name);
$user_password = sha1($user_password);

$result = mysql_query("SELECT `user_id` FROM `users` WHERE `user_name` = '{$user_name}' AND `user_password` = '{$user_password}'");

if (mysql_num_rows($result) != 1){
return false;
}

return mysql_result($result, 0);
}

?>[/syntax]
Last edited by Z645 on Mon Aug 20, 2012 6:56 pm, edited 2 times in total.
User avatar
FrederickGeek8
Posts: 148
Joined: Wed Nov 30, 2011 10:31 pm

Re: Private Messaging System.

Post by FrederickGeek8 »

Umm are you sure you posted the code right? You're saying init.inc.php is exactly the same as user.inc.php...
Z645
Posts: 33
Joined: Thu Jul 26, 2012 5:08 pm

Re: Private Messaging System.

Post by Z645 »

FrederickGeek8 wrote:Umm are you sure you posted the code right? You're saying init.inc.php is exactly the same as user.inc.php...

Fixed. Sorry about that :shock:
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Private Messaging System.

Post by jacek »

You're not including user.inc.php in your init.int.php file so the function is never being defined.
Image
Z645
Posts: 33
Joined: Thu Jul 26, 2012 5:08 pm

Re: Private Messaging System.

Post by Z645 »

jacek wrote:You're not including user.inc.php in your init.int.php file so the function is never being defined.

Ouch. Silly mistakes Hehe. :oops:
Post Reply