not redirecting to protected.php

Ask about a PHP problem here.
Post Reply
robs
Posts: 2
Joined: Sun Mar 11, 2012 12:56 am
Location: US

not redirecting to protected.php

Post 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
Attachments
init.inc.txt
(448 Bytes) Downloaded 59 times
login.txt
(1.35 KiB) Downloaded 62 times
register.txt
(1.13 KiB) Downloaded 57 times
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: not redirecting to protected.php

Post 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.
Image
robs
Posts: 2
Joined: Sun Mar 11, 2012 12:56 am
Location: US

Re: not redirecting to protected.php

Post 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!
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: not redirecting to protected.php

Post 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.
Image
Post Reply