does init.inc.php from user system conflicts wit the init.inc.php from the user profile ?
init.inc.php from user register/login:
<?php
session_start();
$exceptions = array('register', 'login', 'activate');
$page = substr(end(explode('/', $_SERVER['SCRIPT_NAME'])), 0, -4);
mysql_connect('localhost', 'root', '12345678');
mysql_select_db('user_system');
$path = dirname(__FILE__);
include("{$path}/inc/user.inc.php");
if (isset($_COOKIE['username'], $_COOKIE['password']) && isset($_SESSION['username']) === false){
if (valid_credentials($_COOKIE['username'], $_COOKIE['password'])){
$_SESSION['username'] = htmlentities($_COOKIE['username']);
setcookie('username', $_COOKIE['username'], time() + 604800);
setcookie('password', sha1($_COOKIE['password'], time() + 604800));
}
}
if (in_array($page, $exceptions) === false){
if (isset($_SESSION['username']) === false){
header('Location: login.php');
die();
}
}
?>
init.inc.php from user profile
<?php
mysql_connect('localhost', 'root', '12345678');
mysql_select_db('user_system');
$path = dirname(__FILE__);
include("{$path}/inc/user.inc.php");
$_SESSION['uid'] = 1;
?>
can these 2 be mixed together?
Thanks!
And user.inc.php from reg/login can be mixed with user.inc.php from user profile?
user.inc.php from login-reg
<?php
//checks if given username exists in the database.
function user_exists($user){
$user = mysql_real_escape_string($user);
$total = mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `user_name` = '{$user}'");
return (mysql_result($total, 0) == '1') ? true : false;
}
//checks if given username and password conbination is valid.
function valid_credentials($user, $pass){
$user = mysql_real_escape_string($user);
$pass = mysql_real_escape_string($pass);
$total = mysql_query("SELECT COUNT('user_id') FROM `users` WHERE `user_name` = '{$user}' AND `user_password` = '{$pass}'");
return (mysql_result($total, 0) == '1') ? true : false;
}
//checks if the given user account is active.
function is_active($user){
$user = mysql_real_escape_string($user);
$sql = "SELECT
COUNT(`user_activations`.`user_id`)
FROM `users`
INNER JOIN `user_activations`
ON `users`.`user_id`=`user_activations`.`user_id`
WHERE `users`.`user_name` = '{$user}'";
$result = mysql_query($sql);
return (mysql_result($result, 0) == '0') ? true : false;
}
//activates the account related to the given activation code.
function activate_account($aid) {
$aid = mysql_real_escape_string($aid);
mysql_query("DELETE FROM `user_activations` WHERE `activation_code` = '{$aid}'");
}
//adds user to the database.
function add_user($user, $email, $pass){
$user = mysql_real_escape_string(htmlentities($user));
$email = mysql_real_escape_string($email);
$pass = sha1($pass);
$charset = array_flip(array_merge(range('a', 'z'), range('A', 'Z'), range(0, 9)));
$aid = implode('', array_rand($charset, 10));
$body = <<<EMAIL
Hi.
Thanks for registering, before you login you need to activate your account.
To do that, simply click the following link.
D:/XAMPP/xampp/htdocs/Better/activate.php?aid={$aid}
EMAIL;
mail($email, 'Your new account at CupidCity.com', $body, 'From: no-reply@cupidcity.com');
mysql_query("INSERT INTO `users` (`user_name`, `user_password`,`user_email`) VALUES ('{$user}', '{$pass}', '{$email}')");
$user_id = mysql_insert_id();
mysql_query("INSERT INTO `user_activations` (`user_id`, `activation_code`) VALUES ({$user_id}, '{$aid}')");
}
?>
user.inc.php from user profiles:
<?php
//fetches all users from the table.
function fetch_users(){
$result = mysql_query('SELECT `user_id` AS `id`, `user_name` AS `username` FROM `users`');
$users = array();
while (($row = mysql_fetch_assoc($result)) !== false){
$users[] = $row;
}
return $users;
}
//fatches profile information for the given user.
function fetch_user_info($uid){
$uid = (int)$uid;
$sql = "SELECT
`user_name` as `username`,
`user_firstname` as `firstname`,
`user_lastname` as `lastname`,
`user_email` as `email`,
`user_about` as `about`,
`user_location` as `location`,
`user_gender` as `gender`
FROM `users`
WHERE `user_id` = {$uid}";
$result = mysql_query($sql);
return mysql_fetch_assoc($result);
}
//updates the current user profile info.
function set_profile_info($email, $about, $location){
$email = mysql_real_escape_string(htmlentities($email));
$about = mysql_real_escape_string(nl2br(htmlentities($about)));
$location = mysql_real_escape_string($location);
$sql = "UPDATE `users` SET
`user_email` = '{$email}',
`user_about` = '{$about}',
`user_location` = '{$location}'
WHERE `user_id` = {$_SESSION['uid']}";
mysql_query($sql);
}
?>