Jump to content

Login acess problem..


bugzy

Recommended Posts

It is always redirecting me to login page

 

here are the codes

 

login.php

 



if($check_status == 3)
{
				echo "<span class=\"error_validation\">Your account is banned!</span>";
			}
			else
			{	

				$found_user = mysql_fetch_array($result);

				$_SESSION['member_id'] = $found_user['member_id'];

				me_redirect_to('admin/index.php');

}

 

 

admin/index.php

 

<?php require_once("../includes/session.php"); ?>
<?php require_once("../includes/connection.php"); ?>
<?php require_once("../includes/functions.php"); ?>
<?php confirm_logged_in(); ?>

 

 

function confirm_logged_in

 

 

session_start(); 


function confirm_logged_in()
{
if(!isset($_SESSION['member_id']))
{
	me_redirect_to('/prac/login.php');
}
}

 

 

Any idea guys?  :shrug:

Link to comment
Share on other sites

$found_user = mysql_fetch_array($result);

 

Can we see the mysql you used to generate $result? Copying the all the relevant PHP lines would be ideal.

 

 

$query = "Select member_id,email,status from user where email = '{$email}' AND password = '{$hashed_password}' LIMIT 1";
$result = mysql_query($query,$connection) or die (mysql_error());

 

:shrug:

Link to comment
Share on other sites

I don't see a session_start() in login.php. Without that, it would cause $_SESSION['member_id'] to be unset, and result in being redirected to login.php.

 

Sorry I didn't say on my 1st post that

 

<?php require_once("includes/session.php"); ?>

 

is also at the very top of login.php

 

so what do you think guys is the problem

 

 

Link to comment
Share on other sites

Do you have any error suppression on?

 

If not, we really need to see more of your PHP. If the error is in the code you've posted, you haven't provided enough context for us to find it.

 

From what we can see of what you posted, there's no reason your code isn't working. We need to see more.

Link to comment
Share on other sites

Since you're only showing us a select part of the code, we can only really stab at the answer.

 

If both session.php and functions.php contain session_start(); you should be getting a notice. You should probably turn ALL error reporting on when developing. When things go wrong, comment out redirects and check for errors.

Link to comment
Share on other sites

Ok it seemed like I know where the problem is now but I don't know why it is happening....

 

the problem is on the login form.

 

The code where I think the problem is on base on trial and error

 


		$query = "Select member_id,email,status from user where email = '{$email}' AND password = '{$hashed_password}' LIMIT 1";
		$result = mysql_query($query,$connection) or die (mysql_error());
		$num_user = mysql_num_rows($result);



		if($num_user == 1)
		{

			$time_query = "UPDATE user set last_login=NOW() where email = '{$email}' LIMIT 1";
			$time_result = mysql_query($time_query,$connection) or die (mysql_error());


			$check_status = mysql_result($result,0,'status');


			if($check_status == 3)
			{
				echo "<span class=\"error_validation\">Your account is banned!</span>";
			}
			else
			{	

				$found_user = mysql_fetch_array($result);

				$_SESSION['member_id'] = $found_user['member_id'];


				me_redirect_to('admin/index.php');



			}


		}
		else
		{
			echo "<span class=\"error_validation\">E-mail/Password combination is incorrect.<br>Pls. make sure that your CAPS LOCK is off and try again.</span>";
		}



	}

 

 

 

 

The problem is on these lines

 

$check_status = mysql_result($result,0,'status');


			if($check_status == 3)
			{
				echo "<span class=\"error_validation\">Your account is banned!</span>";
			}

 

 

If I remove it.. The code works fine but if it is there I'm not getting any value on

 

$_SESSION['member_id'] = $found_user['member_id'];

 

and is returning

 

Array ( [member_id] => )

 

 

it's not the IF first statement but this

 

$check_status = mysql_result($result,0,'status');

 

I wonder why it is happening... Anyone?  :confused:

Link to comment
Share on other sites

From the manual entry for mysql_result(): Calls to mysql_result() should not be mixed with calls to other functions that deal with the result set.

 

When you call mysql_result(), you advance the internal data pointer to the next record, which doesn't exist because the results set is LIMITed to 1 record (and that's all there should be anyhow). Then when you call mysql_fetch_array(), there is no record for it to act on. You either need to move the pointer back to the first record, which isn't what I"d recommend here, or rearrange your logic so it makes all of its "decisions" on the result set at the same time.

Link to comment
Share on other sites

From the manual entry for mysql_result(): Calls to mysql_result() should not be mixed with calls to other functions that deal with the result set.

 

When you call mysql_result(), you advance the internal data pointer to the next record, which doesn't exist because the results set is LIMITed to 1 record (and that's all there should be anyhow). Then when you call mysql_fetch_array(), there is no record for it to act on. You either need to move the pointer back to the first record, which isn't what I"d recommend here, or rearrange your logic so it makes all of its "decisions" on the result set at the same time.

 

Pikachu2000 thanks you for explaining it clearly!

 

Now instead of me using mysql_result I have use

 

$found_user = mysql_fetch_array($result);

$found_user['status']

 

instead. Thanks guys!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.