Page 1 of 1
Getting errors in the reg / login system
Posted: Tue Jun 04, 2013 1:16 am
by torger
Errors:
Warning: include(loginsystem/init.inc.php): failed to open stream: No such file or directory in C:\xampp\htdocs\loginsystem\register.php on line 3
Warning: include(): Failed opening 'loginsystem/init.inc.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\loginsystem\register.php on line 3
Fatal error: Call to undefined function user_exists() in C:\xampp\htdocs\loginsystem\register.php on line 18
line 18 looks like this:
if (user_exists($_POST['username'])){
$errors[] = 'The username you entered is already taken.';
line 3 looks like this:
include('loginsystem/init.inc.php');
added, the register.php file.
Re: Getting errors in the reg / login system
Posted: Tue Jun 04, 2013 1:19 am
by torger
i also get this error:
Warning: include(): Failed opening 'C:\xampp\htdocs\loginsystem/loginsystem/user.inc.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\loginsystem\init.inc.php on line 22
line 22 init.inc.php looks like this:
include("{$path}/loginsystem/user.inc.php");
Re: Getting errors in the reg / login system
Posted: Tue Jun 04, 2013 7:53 am
by Helx
Please post the entire PHP file in syntax tags (the "PHP" button in the editor).
The error you got was because of PHP not being able to find the file you're suggesting.
I would guess that there's an issue with the variable $path that you're setting, though we can't know this unless you give us the entire file
If you have any visible MySQL passwords, it'd be a good idea to remove it (though don't edit the original).
NOTE: Moved from user-submitted tutorials sub-forum to support tutorials sub-forum.
Re: Getting errors in the reg / login system
Posted: Tue Jun 04, 2013 10:23 am
by torger
ah ok.
here it is
<?php
include('loginsystem/init.inc.php');
$errors = array ();
if (isset($_POST['username'], $_POST['password'], $_POST['repeat_password'])){
if (empty($_POST['username'])){
$errors[] = 'The username cannot be empty.';
}
if (empty($_POST['password']) || empty($_POST['repeat_password'])){
$errors[] = 'The password cannot be empty.';
}
if ($_POST['password'] !== $_POST['repeat_password']){
$errors[] = 'Password verification failed.';
}
if (user_exists($_POST['username'])){
$errors[] = 'The username you entered is already taken.';
}
if (empty($errors)){
add_user($_POST['username'], $_POST['password']);
$_SESSION['username'] = htmlentities($_POST['username']);
header('Location: protected.php');
die();
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css href="ext/css/style.css" />
<title>lol</title>
</head>
<body>
<div>
<?php
if (empty($errors) === false){
?>
<ul>
<?php
foreach ($errors as $error){
echo "<li>{$error}</li>";
}
?>
</ul>
<?php
}
?>
</div>
<form action="" method="post">
<p>
<label for="username">Username:</label>
<input type="text" name="username" id="username" value"<?php if (isset($_POST['username'])) echo htmlentities($_POST['username']); ?>" />
</p>
<p>
<label for ="password">password:</label>
<input type="password" name="password" id="password" />
</p>
<p>
<label for="repeat_password">repeat password:</label>
<input type="password" name="repeat_password" id="repeat_password" />
</p>
<p>
<input type="submit" value="register" />
</p>
</form>
</body>
</html>
<?php
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;
}
function valid_credentials($user, $pass){
$user = mysql_real_escape_string($user);
$pass = sha1($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;
}
function add_user($user, $pass){
$user = mysql_real_escape_string(htmlentities($user));
$pass = sha1($pass);
mysql_query("INSERT INTO `users` (`user_name`, `user_password`) VALUES ('{$user}', '{pass}')");
}
?>
<?php
session_start();
$exceptions = array('register', 'login');
$page = substr(end(explode('/', $_SERVER['SCRIPT_NAME'])), 0, -4);
if (in_array($page, $exceptions) === false){
if (isset($_SESSION['username']) === false){
header('Location: login.php');
die();
}
}
mysql_connect('127.0.0.1', 'root', '..pw..');
mysql_select_db('user_system');
$path = dirname(__FILE__);
include("{$path}/loginsystem/user.inc.php");
?>
<?php
include('init.inc.php');
$errors = array();
if (isset($_POST['username'], $_POST['password'])){
if (empty($_POST['username'])){
$errors[] = 'The username cannot be empty.';
}
if (empty($_POST['password'])){
$errors[] = 'The password cannot be empty.';
}
if (empty($errors) && valid_credentials($_POST['username'], $_POST['password'])=== false){
$errors[] = 'username / Password incorrect.';
}
if (empty($errors)){
$_SESSION['username'] = htmlentities($_POST['username']);
header('Location: protected.php');
die();
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css href="ext/css/style.css" />
<title>lol</title>
</head>
<body>
<div>
<?php
if (empty($errors) === false){
?>
<ul>
<?php
foreach ($errors as $error){
echo "<li>{error}</li>";
}
?>
</ul>
<?php
}else{
echo 'need an account ? <a href="register.php">Register here</a>';
}
?>
</div>
<form action="" method="post">
<p>
<label for="username">Username:</label>
<input type="text" name="username" id="username" value"<?php if (isset($_POST['username'])) echo htmlentities($_POST['username']); ?>" />
</p>
<p>
<label for="password">Password:</label>
<input type="password" name="password" id="password" />
</p>
<p>
<input type="submit" value="Login" />
</p>
</form>
</body>
</html>
<?php include('init.inc.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>lol</title>
</head>
<body>
<p>
You are logged in as <?php echo $_SESSION['username']; ?>
</p>
<p>
<a href="logout.php">Logout ?</a>
</p>
</body>
</html>
Re: Getting errors in the reg / login system
Posted: Tue Jun 04, 2013 10:32 am
by Helx
Line 3 of the first block of code you gave.
You're using Windows, so you don't follow Linux/UNIX file structure.
Change "/" to "\" ONLY on line 3
Re: Getting errors in the reg / login system
Posted: Tue Jun 04, 2013 11:35 am
by torger
Im using xampp, i tryed to change it but nothing happend Oo
Re: Getting errors in the reg / login system
Posted: Thu Jun 06, 2013 8:34 pm
by FrederickGeek8
Go to your php.ini and look for a line that says something like
include_path "yadayadayada"
If you delete that line, then it should work (I don't know how xampp works so you might need to restart stuff)
I don't know where it is in php.ini but my best guess is it is near the bottom. This problem is normally caused by the installation of PEAR. Sometimes when installer it places that near the bottom of the php.ini file and causes problems.
[
Source]