Page 1 of 1

not redirecting to protected.php

Posted: Sun Mar 11, 2012 1:10 am
by robs
Hello everyone, I am new to php, but got most of this working. I am able to register users, however when I submit registration it redirects me to the login form, and skips the protected.php, also when logging in with an already registered user, it does the same thing. I am assuming this has to do with the session. but can't seem to figure this one out.

i've uploaded my register.php, login.php, and init.inc.php file, and could not upload the protected page due to the sites security so i've just pasted below. Thanks is advance for the help!
<?php include('core/init.inc.php'); ?>

<html>
	<head>
		<title></title>
	</head>
	<body>
		<p>
		You are logged in as <?php echo $_SESSION['username'] ?>
		</p>
		<p>
		<a href="logout.php">Logout?</a>
		</p>	
	</body>
</html>
-Rob

Re: not redirecting to protected.php

Posted: Sun Mar 11, 2012 1:26 am
by jacek
In the init.in.php file you have
$path = dirname(_FILE_);
The file constant here should have two _ either side of it.

I cant see anything else wrong :? Try fixing that and see where it leaves you.

Re: not redirecting to protected.php

Posted: Sun Mar 11, 2012 1:38 am
by robs
Ahh yes, that got me past that, now getting:

Warning: mysql_result() expects parameter 1 to be resource, boolean given in /home/content/64/7274864/html/musicspot2/core/inc/user.inc.php on line 9

Fatal error: Call to undefined function htmlentites() in /home/content/64/7274864/html/musicspot2/core/inc/user.inc.php on line 24
<?php
 
// Checks if the given username exists in the database.
function user_exists($user){
	
$user = mysql_real_escape_string($user);
	
	
$total = mysql_query("SELECT COUNT(`user_id`) FROM `users2` WHERE `user_name` = '{$user}'");
	
	return (mysql_result($total, 0) == '1') ? true : false;
}

 
// Checks is the given username and password combination is valid. 
function valid_credentials($user, $pass){
        $user = mysql_real_escape_string($user);
        $pass = sha1($pass);
        $total = mysql_query("SELECT COUNT(`user_id`) FROM `users2` 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($user);
        $pass = sha1($pass);
        mysql_query("INSERT INTO `users2` (`user_name`, `user_password`) VALUES ('{$user}', '{$pass}')");
}
 
?>

users2 is the correct name for my DB. Thank you for the super fast reply on the last post!

Re: not redirecting to protected.php

Posted: Mon Mar 12, 2012 8:18 pm
by jacek
robs wrote:Fatal error: Call to undefined function htmlentites() in /home/content/64/7274864/html/musicspot2/core/inc/user.inc.php on line 24
You spelled entities wrong, you need the second i en-tities ;)
robs wrote:Warning: mysql_result() expects parameter 1 to be resource, boolean given in /home/content/64/7274864/html/musicspot2/core/inc/user.inc.php on line 9
Cant see anything wrong right away, that error means the serer failed on your query for some reason. If you add
echo mysql_error();
after the mysql_query() it should tell you why.