registry problems
-
- Posts: 8
- Joined: Thu Sep 05, 2013 4:01 am
registry problems
Hello, I have recently watched PHP Tutorial: Register and Login (User Account System) [part 04] and have typed down everything that was written down but when I go to my registry.php page it says {$error}"; } ?> at the top, and if I dont fill out a row (which is supposed to bring up an error message) it still says {$error}"; } ?>. Also when I do fill out all the lines, the page doesn't go to protected.php but just refreshes the page. How do I fix this?
register.php
[syntax=php]<?php
include('core\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();
}
}
?>
<html>
<head>
<title>The Video Network</title>
</head>
<body bgcolor="59D7F0">
<div>
<?php
if (empty($errors) === false){
?>
<ul>
<?php
foreach ($errors as $error){
echo "<li>{$error}</li>";
}
?>
</ul>
<?php
}
?>
</div>
<table>
<tr>
<td><a href="homepage.php"><img src="ext\images\logo.png"></a></td>
<td><font size="5" color="59D7F0"><B>fille</B></font>
<td><img src="ext\images\topuploaders.png"></td>
<td><img src="ext\images\mostloved.png"></td>
<td><img src="ext\images\mostview.png"></td>
<td><font size="5" color="59D7F0"><B>fille</B></font>
<td><a href="login-register/login.php"><img src="ext\images\login.png"></a></td>
</tr>
</table>
<br>
<br>
<br>
<br>
<br>
<br>
<center>
<form action="" method="post">
<p>
<label for="username"> Username:</label>
<input type="text" name="username" id="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>
</center>
</body>
</html>[/syntax]
protected.php
[syntax=php]<?php include('core\init.inc.php'); ?>
<html>
<head>
<title>Login|The Video Network</title>
</head>
<body>
<p>
You are logged in as <?php ?>
</p>
</body>
</html>[/syntax]
init.inc.php
[syntax=php]<?php
session_start();
$exceptions = array('register', 'login');
if (in_array($page, $exceptions) === false){
if (isset($_SESSION['username']) === false){
header('location: login.php');
die();
}
}
mysql_connect('10.0.0.1', 'example_pass', 'example_pass');
mysql_select_db('user_system');
$path = dirname(_FILE_);
include("{$path}/inc/user.inc.php");
?>[/syntax]
user.inc.php
[syntax]<?php
// checks if the given username exists in the table
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;
}
// check if the given username and password combination is valid.
function valid_credentials($user, $pass){
$user = mysql_real_escape_string($user);
$pass = shal($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;
}
// adds a user to the database.
function add_user($user, $pass){
$user = mysql_real_escape_string(htmlentities($user));
$pass = shal($pass);
mysql_query("INSERT INTO 'users' ('user_name', 'user_password') VALUES ('{$user}', '{$pass}')");
}
?> [/syntax]
register.php
[syntax=php]<?php
include('core\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();
}
}
?>
<html>
<head>
<title>The Video Network</title>
</head>
<body bgcolor="59D7F0">
<div>
<?php
if (empty($errors) === false){
?>
<ul>
<?php
foreach ($errors as $error){
echo "<li>{$error}</li>";
}
?>
</ul>
<?php
}
?>
</div>
<table>
<tr>
<td><a href="homepage.php"><img src="ext\images\logo.png"></a></td>
<td><font size="5" color="59D7F0"><B>fille</B></font>
<td><img src="ext\images\topuploaders.png"></td>
<td><img src="ext\images\mostloved.png"></td>
<td><img src="ext\images\mostview.png"></td>
<td><font size="5" color="59D7F0"><B>fille</B></font>
<td><a href="login-register/login.php"><img src="ext\images\login.png"></a></td>
</tr>
</table>
<br>
<br>
<br>
<br>
<br>
<br>
<center>
<form action="" method="post">
<p>
<label for="username"> Username:</label>
<input type="text" name="username" id="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>
</center>
</body>
</html>[/syntax]
protected.php
[syntax=php]<?php include('core\init.inc.php'); ?>
<html>
<head>
<title>Login|The Video Network</title>
</head>
<body>
<p>
You are logged in as <?php ?>
</p>
</body>
</html>[/syntax]
init.inc.php
[syntax=php]<?php
session_start();
$exceptions = array('register', 'login');
if (in_array($page, $exceptions) === false){
if (isset($_SESSION['username']) === false){
header('location: login.php');
die();
}
}
mysql_connect('10.0.0.1', 'example_pass', 'example_pass');
mysql_select_db('user_system');
$path = dirname(_FILE_);
include("{$path}/inc/user.inc.php");
?>[/syntax]
user.inc.php
[syntax]<?php
// checks if the given username exists in the table
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;
}
// check if the given username and password combination is valid.
function valid_credentials($user, $pass){
$user = mysql_real_escape_string($user);
$pass = shal($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;
}
// adds a user to the database.
function add_user($user, $pass){
$user = mysql_real_escape_string(htmlentities($user));
$pass = shal($pass);
mysql_query("INSERT INTO 'users' ('user_name', 'user_password') VALUES ('{$user}', '{$pass}')");
}
?> [/syntax]
Last edited by doomrancher on Fri Sep 20, 2013 5:22 am, edited 4 times in total.
Re: registry problems
can you post the code for ini.inc.php as well?
And please post the code here inside code tags. I don't like pastebin very much.
And please post the code here inside code tags. I don't like pastebin very much.
-
- Posts: 8
- Joined: Thu Sep 05, 2013 4:01 am
Re: registry problems
ok i put up protected.php and init.inc.php as well
Re: registry problems
Okay, the problem is instantly visible when you have syntax highlighting on.
You can clearly see that the highlighting breaks on line 9 in init.inc.php.
This is because you have one too many ending semicolons ( ; ). You should have one at the end of the line only. Remove the one after $_SERVER['SCRIPT_NAME']).
/Edit; I would also recommend you getting a text editor with syntax highlighting on, such as Notepad++
You can clearly see that the highlighting breaks on line 9 in init.inc.php.
This is because you have one too many ending semicolons ( ; ). You should have one at the end of the line only. Remove the one after $_SERVER['SCRIPT_NAME']).
/Edit; I would also recommend you getting a text editor with syntax highlighting on, such as Notepad++
-
- Posts: 8
- Joined: Thu Sep 05, 2013 4:01 am
Re: registry problems
i fixed the thing with the init.inc.php file but it's still not working
Re: registry problems
You are missing a semicolon after your header redirect.
<?php while(!$succeed = try()); ?>
Re: registry problems
doomrancher wrote:in which script?
the same script.
-
- Posts: 8
- Joined: Thu Sep 05, 2013 4:01 am
Re: registry problems
i put in the semicolon but it still does the same thing
Re: registry problems
and what is this " same thing " ? "Not Working" is not very specific.
Do you get an error message?
Does it just refresh and not do anything?
Does it redirect you?
I can't guess my way to what's wrong.
Try turning on error reporting.
Put this in the top of init.inc.php:
[syntax=php]error_reporting(E_ALL);
ini_set('display_errors', 1);[/syntax]
Do you get an error message?
Does it just refresh and not do anything?
Does it redirect you?
I can't guess my way to what's wrong.
Try turning on error reporting.
Put this in the top of init.inc.php:
[syntax=php]error_reporting(E_ALL);
ini_set('display_errors', 1);[/syntax]
-
- Posts: 8
- Joined: Thu Sep 05, 2013 4:01 am
Re: registry problems
i don't get an error message, and it doesnt redirect me but it does refresh and not do anything.
plus the error reporting thing didnt work
plus the error reporting thing didnt work
Re: registry problems
You posted init.inc.php. user.inc.php contains all the functions to make it work.
<?php while(!$succeed = try()); ?>
-
- Posts: 8
- Joined: Thu Sep 05, 2013 4:01 am
Re: registry problems
oh ok its posted now