Welcome Guest, Not a member yet? Register   Sign In
problem in redirect method
#1

[eluser]asmaa kamal[/eluser]
hi
i try to code login page to website

i got this error

Quote:Not Found

The requested URL /t/main/login was not found on this server.

i got this error if i login by accepted email, password or if i login by unaccepted one

this is main code(in controller)

Code:
<?php

class Main extends CI_Controller {
function Main()
{
parent::__construct();


$this->load->model('user_model');


}

  public function login()
  {
  $this->form_validation->set_rules('userEmail','email','trim|required|valid_email|callback_check_login');
   $this->form_validation->set_rules('userPassward','passward','trim|required');
  
  if($this->form_validation->run())
  {
  
if($this->user_model->Login(array('userEmail'=>$this->input->post('userEmail'),'userPassward'=>$this->input->post('userPassword'))));
   {redirect('dashboard');}
   redirect('main/login');}
  
  $this->load->view('main/login_form');
  }
  function index()
{
  $this->load->view('main/main_index');
}
function _check_login($userEmail)
{
if ($this->input->post('userPassward'))
{
$user=$this->user_model->GetUsers(array('userEmail'=>$userEmail,'userPassward'=>md5($this->input->post('userPassword'))));
if($user) return true;
}
$this->form_validation->set_message('_check_login','your username/passward is invalid.');
return false;


}
}


and this is view code

Code:
<?php echo form_open(base_url() . 'main/login')?>
<fieldset>
<legend>Login Form </legend>
<ul>
<li>
<label>Email</label>
&lt;?php echo form_input('userEmail',set_value('userEmail'))?&gt;
&lt;?php echo form_error('userEmail')?&gt;
</li>
<li>
<label>password</label>
&lt;?php echo form_password('userPassword')?&gt;
&lt;?php echo form_error('userPassword')?&gt;
</li>
<li>
&lt;?php echo form_submit('','login')?&gt;
</li>
</ul>

</fieldset>
&lt;?form_close()?&gt;


and this is model code

Code:
&lt;?php

class User_Model extends Model {

function _required($required,$data)
{
foreach($required as $field)
if(!isset($data[$field])) return false;
return true;

}


function AddUser($options=array())
{
if(!$this->_required(array('userEmail','userPassword'),$options)) return false;
$options=$this->_default(array('userStatus','active'),$options);
$this->db->insert('users',$options);
return $this->db->insert_id();





}
function UpdateUser($options=array())
{
if(!$this->_required(array('userId'),$options)) return false;
if(isset($options['userEmail']))
$this->db->set('userEmail',$options['userEmail']);
if(isset($options['userPassword']))
$this->db->set('userPassword',md5($options['userPassword']));
if(isset($options['userStatus']))
$this->db->set('userStatus',$options['userStatus']);
$this->db->update('users');
return $this->db->affected_rows();



}
function _default($defaults,$options)
{
return array_merge($defaults,$options);

}
function GetUsers($options=array())
{
if(isset($options['userId']))
$this->db->where('userId',$options['userId']);
if(isset($options['userEmail']))
$this->db->where('userEmail',$options['userEmail']);
if(isset($options['userStatus']))
$this->db->where('userStatus',$options['userStatus']);
if(isset($options['userPassword']))
$this->db->where('userPassword',$options['userPassword']);
if(isset($options['limit'])&&isset;($options['offset']))
$this->db->limit($options['limit'],$options['offset']);
else if(isset($options['limit']))
$this->db->limit($options['limit']);
if(isset($options['sortBy'])&&isset;($options['sortDirection']))
$this->db->order_by($options['sortBy'],$options['sortDirection']);
$query=$this->db->get('users');
if(isset($options['userId'])||isset($options['userEmail']))
return $query->row(0);
return $query->result();

}
function Login($options=array())
{
if(!$this->_required(array('userEmail','userPassword'),$options)) return false;
$user=$this->GetUsers(array('userEmail'=>$options['userEmail'],'userPassword'=>md5($options['userPassword'])));
if(!$user) return false;
$this->session->set_userdata('userEmail',$user->userEmail);

$this->session->set_userdata('userId',$user->userId);
return true ;
}

}






?&gt;


i think the problem in redirect method ( in main in controller) but when i stop this part i got the same error and when i try this
Code:
if($this->user_model->Login(array('userEmail'=>$this->input->post('userEmail'),'userPassward'=>$this->input->post('userPassword'))));
   {redirect('index.php/dashboard');}
   redirect('index.php/main/login');}


plz help me

thanks Smile
#2

[eluser]Jason Stanley[/eluser]
What is your base url? Is your site nested in a folder called 't'?
#3

[eluser]asmaa kamal[/eluser]
iam working at "local host" using wamp

the folder t is codeigniter folder it contains (application-system-userguide)

look at this


Code:
$config['base_url'] = '';

$config['index_page'] = '';

$config['url_suffix'] = '';
#4

[eluser]Jason Stanley[/eluser]
Why haven't you filled out the base url?

Its Step 3 on the installation instructions.
http://ellislab.com/codeigniter/user-gui...index.html

This will probably solve your problem. Currently it looks like CI is interpreting your directory as a controller.
#5

[eluser]asmaa kamal[/eluser]
i put it
$config['base_url'] = 'wathba.team'or 't' or 'index.php';
but it doesnt solve the problem
i dont know what i put in base url
i dont have url iam working at localhost
sorry iam beginner
#6

[eluser]Jason Stanley[/eluser]
What is the url to your codeigniter install?

Quote:http://localhost/t/

Is that it? What are you putting in the browser?
#7

[eluser]asmaa kamal[/eluser]
@jason Stanley

when i put :http://localhost/t/index.php/main/login

it give me the form

Email
password
i put email(true )exist in database
i got this message : Not Found

The requested URL /t/main/login was not found on this server.

and the url become :http://localhost/t/main/login

if i let textboxes blank and submit >> i got the same message
#8

[eluser]PhilTem[/eluser]
If you're working on wamp and have problems with the mod_rewrite, try to set 'index_page' to 'index.php' than it should solve your problem(s).
#9

[eluser]asmaa kamal[/eluser]
@PhilTem


i put

$config['index_page'] = 'index.php';

but the problem still exist
#10

[eluser]Jason Stanley[/eluser]
Your redirect code doesn't need the index.php in it.

Code:
redirect('main/login')

You config options should look like this.
Code:
$config['base_url'] = 'http://localhost/t/'; // The url of your local site.
$config['index_page'] = 'index.php';




Theme © iAndrew 2016 - Forum software by © MyBB