If logged in...

Post here is you are having problems with any of the tutorials.
Post Reply
User avatar
kalipsso
Posts: 30
Joined: Thu Jun 09, 2011 3:03 pm
Location: Bucharest
Contact:

If logged in...

Post by kalipsso »

I made this code for users that are logged in to "Not see the log-in form" when if they are logged in.
It works when i am logged in, but where i log-out, i cant access the log-in form. I am getting this:
The page isn't redirecting properly

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

This problem can sometimes be caused by disabling or refusing to accept
cookies.
Here is the code:
if(is_logged_in) {
  header("Location: edit_profile.php");
  }
else {
  header("Location: login.php");
  }
What have i done wrong??

i have also made changes in user.inc.php file:
//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}'");
	$total = mysql_query("SELECT * FROM `users` WHERE `user_name` = '{$user}' AND `user_password` = '{$pass}'");
    if($total)
        {
        if(mysql_num_rows($total) > 0)
            {
            $_SESSION['uid'] = mysql_result($total, 0, "user_id");
            //Add session variables here if needed
            
            return true;
            }
        else
            {
            return false;
            }
        }
    else
        {
        return false;
        }
	//return (mysql_result($total, 0) == '1') ? true : false;
}
Tino
Posts: 360
Joined: Thu May 05, 2011 8:55 pm
Location: The Netherlands

Re: If logged in...

Post by Tino »

What is 'is_logged_in'?

The reason for that error is because you are apparently redirecting to a page that will immediately redirect again. For example, if you have

page1.php
if ( 1 === 1 ) {
    header('Location: page2.php');
}
page2.php
if ( 2 === 2 ) {
    header('Location: page1.php');
you essentially get the same effect as an infinite loop.
Please check out my CodeCanyon items.
User avatar
kalipsso
Posts: 30
Joined: Thu Jun 09, 2011 3:03 pm
Location: Bucharest
Contact:

Re: If logged in...

Post by kalipsso »

Do you have any solution?
Regards and thanks for the fast reply.
User avatar
kalipsso
Posts: 30
Joined: Thu Jun 09, 2011 3:03 pm
Location: Bucharest
Contact:

Re: If logged in...

Post by kalipsso »

OK.
I have found a solution...
<?php
		if (isset($_SESSION['username']) === false){
	?>

form here

<?php
	}else{
	echo "Welcome <a href='profile.php'>" . $_SESSION['username']."</a> ! - <a href='logout.php'>Logout</a>.";
 }
?>

Just in case someone else will need it.
I also modified the profile.php file to display the logged in user profile...
Post Reply