Welcome Guest, Not a member yet? Register   Sign In
Redirect
#1

[eluser]james byrne[/eluser]
I have a problem in my application, it is just a simple login now. But when the user logins in, which uses the login function. It woks fine, But if for some reason i then load the index function or refresh the page. It redirects to the login function, which because the user is logged in redirects back to index. So it gets in a big loop. I can post the code if needed but can someone give me a idea of what is going on here. and why? Thanks in advance.
#2

[eluser]ejangi[/eluser]
The code would be helpful. Are you using sessions to validate that the user is logged in? Based on the information you've given it sounds like after refresh the system is not recognising that the user is logged in and therefore redirects them back to the login screen.
#3

[eluser]imzyos[/eluser]
yeah, use session's or cookies, and you mus validate according to them, not just by the execution of the function
#4

[eluser]james byrne[/eluser]
I can not figure it out can someone look at my code and let me know what is up. Thanks in advance for your help:

<?php

class Admin extends Controller {

function Admin() {
parent::Controller();

$this->load->helper(array('url','form','date'));
$this->load->library('session');
$this->load->library('validation');
$this->load->library('password');
$this->load->library('email');
}

function index() {
$username = $this->session->userdata('bidder_first_name');

$data['john'] = "This is just a test";

$this->load->view('admin',$data);
}

function login() {

if($this->session->userdata('bidder_logged_in')=="true") {
redirect('admin/index');
}

if(@$_POST["submitted"] == "true") {

$username = @$_POST["bidder_username"];
$password = $this->password->encrypt(@$_POST["bidder_password"]);

$array = array('email'=>$username, 'password'=>$password);
$this->db->where($array);
$this->db->from("users");
$result = $this->db->get();

if($result->num_rows() < 1) {
$data['error'] = "The username/password you provided was incorrect. Please try again.";
$this->load->view('login',$data);
} else {
$array = array('bidder_first_name'=>$result->row()->first_name,
'bidder_username'=>$result->row()->email,
'bidder_logged_in'=>true,
"bidder_id"=>$result->row()->id);
$this->session->set_userdata($array);
redirect('admin/index/');
}
} else {
$this->load->view('login');
}
}

function logout() {
$this->session->sess_destroy();
redirect('admin/');
}

function new_user() {

}
}
?&gt;
#5

[eluser]tonanbarbarian[/eluser]
do you have something in the admin view file that is redirecting?
because there is no reason that the admin/index would redirect to admin/login, not in the controller code
#6

[eluser]james byrne[/eluser]
here is my admin view file. I do not think it has anything to redirect


&lt;?php

include("header.php");

echo "<select name='org_id'>";
foreach($query->result() as $row):
echo "<option>" . $row->item_number . "</option>";
endforeach;

echo "</select>";
?&gt;


<table border="1" cellpading="15" cellspaceing="0">
<tr collspan="3" allign="center"><td>Item box</td><td>Item 2 box</td><td>Item 3 box</td></tr>
<tr><td><img src="&lt;?="localhost/" . $db_name . "/images/jeff.jpg"?&gt;"></td><td>Bid item 2</td><td>Bid item 3</td></tr>
<tr><td>Current item 1</td><td>Current item 2</td><td>Current item 3</td></tr>
</table>
&lt;/body&gt;&lt;/html&gt;
#7

[eluser]tonanbarbarian[/eluser]
ok so what is in header.php?

You have said that something is redirecting from admin/index to admin/login and it cannot be the controller code so it must be something else
#8

[eluser]james byrne[/eluser]
Yes i did say it was redirecting, but if i even remove the call to the view file in CI it still redirects. I just put a echo in. and it still is redirecting. So it is somewhere in the controller file that is posted above.
#9

[eluser]tonanbarbarian[/eluser]
ok i was explaining in another post about a possible problem

If you have a method in a controller called "login" for example, and you have a model or library with a method or property with the same name there can be issues with unexpected things happening because of the way CI instantiates its objects

some examples I have seen before
controller, library or model methods called "view" (they conflict with $this->load->view)
your login method might be a problem

so go through any custom libraries or models you have created and see if you have methods with the same names as existing one.
I know this is a bit of a pain but I have had the "view" problem before.

It is the only thing I can think of that might explain what is happening for you.
#10

[eluser]james byrne[/eluser]
I found the problem even though i do not understand what is happening. But it is the session value "bidder_loged_in" must be changed to "admin_loged_in". can someone please explain why this it.




Theme © iAndrew 2016 - Forum software by © MyBB