CodeIgniter Forums
redirect not working - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: redirect not working (/showthread.php?tid=465)

Pages: 1 2


redirect not working - hadeel - 12-08-2014

Hi,
my redirect function to admin dashboard is not working but it was working yesterday i have tried every thing in .htaccess and config and route files i dont know what to do?
is it need to update codeigniter ?


RE: redirect not working - sv3tli0 - 12-08-2014

There must be some kind of change on your script/server so something working yesterday not to work today.
How ever if you want help you have to show us your code where the bug is coming out else how the hell we can know what is causing it ?


RE: redirect not working - hadeel - 12-08-2014

this is my htaccess :
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|images|img|js|sexyimages|media|roleimages|lang|uploads|files|profile|audio|video|videoplayer|talentimages|captcha|gmap|timthumb|include|ckeditor|webfonts|player|robots\.txt|css|sitemap\.xml|sitemap\.html|BingSiteAuth\.xml)
RewriteRule ^(.*)$ ./index.php/$1 [L]

</IfModule>

and this is my admin login code
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends CI_Controller {



function __construct()
{
// Call the Model constructor
parent::__construct();
$this->load->model('admin/adminloginmodel','', TRUE);
$this->load->library('session');
}

public function index()
{
//$objResponse=new xajaxResponse();
$this->load->helper('url');
$data['msg']= '';
if(isset($_POST['submit']))
{

$msg=$this->adminloginmodel->check_adminlogin();
//echo $msg;
if($msg != 'success')
{
//redirect('admin/dashboard', 'refresh');
$data['msg']= $msg;
}
else
{
redirect(site_url('admin/dashboard'));

}

}

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

/* End of file home.php */
/* Location: ./application/controllers/home.php */


RE: redirect not working - InsiteFX - 12-08-2014

Code:
<IfModule mod_rewrite.c>

    # Make sure directory listing is disabled
    Options +FollowSymLinks -Indexes
    RewriteEngine on

    # NOTICE: If you get a 404 play with combinations of the following commented out lines
    #AllowOverride All
    #RewriteBase /wherever/ci/is
    RewriteBase /

    # Send request via index.php (again, not if its a real file or folder)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteCond $1 ^(robots\.txt|favicon\.ico|style\.css)

    # deal with php5-cgi first
    <IfModule mod_fcgid.c>
        RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
    </IfModule>

    <IfModule !mod_fcgid.c>

        # for normal Apache installations
        <IfModule mod_php5.c>
            RewriteRule ^(.*)$ index.php/$1 [QSA,L]
        </IfModule>

        # for Apache FCGI installations
        <IfModule !mod_php5.c>
            RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
        </IfModule>

    </IfModule>

</IfModule>



RE: redirect not working - hadeel - 12-08-2014

i tried your code its now showing 404 not found error
before it was loading the admin login form
but the redirecting to dashboard after that showing empty page
actually all login forms not working on the website


RE: redirect not working - Avenirer - 12-08-2014

i see that your redirect is commented


PHP Code:
//redirect('admin/dashboard', 'refresh'); 



maybe that is the problem?


RE: redirect not working - hadeel - 12-08-2014

I tried that also still not working Sad


RE: redirect not working - Dracula - 12-09-2014

(12-08-2014, 01:09 PM)hadeel Wrote: I tried that also still not working Sad

Replace this in your controller

PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Home extends CI_Controller {


    public function 
__construct()
    {
        
// Call the Model constructor
        
parent::__construct();
        
$this->load->model('admin/adminloginmodel');

        
// Load your helpers / drivers / libraries globaly from the autoload.php file. You will need them across you app, not just here.
        
$this->load->library('session');
        
$this->load->helper('url');
    }

    public function 
index()
    {
        
//$objResponse=new xajaxResponse();
        
$data['msg']= '';

        if(isset(
$_POST['submit']))
        {
            
$msg=$this->adminloginmodel->check_adminlogin();
            
//echo $msg;
            
if($msg != 'success')
            {
                
$data['msg']= $msg;
                
redirect('admin/dashboard''refresh');

            } else {
                
redirect('admin/dashboard');
            }
        }
        
$this->load->view('admin/adminhome_view',$data);
    }


}
/* End of file home.php */
/* Location: ./application/controllers/home.php */ 


And this in your .htaccess file


Code:
<IfModule mod_rewrite.c>

 Options +FollowSymLinks
 RewriteEngine on

 # Send request via index.php
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d

 RewriteCond $1 ^(robots\.txt|favicon\.ico|style\.css)

   # deal with php5-cgi first
   <IfModule mod_fcgid.c>
       RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
   </IfModule>

   <IfModule !mod_fcgid.c>
       # for normal Apache installations
       <IfModule mod_php5.c>
           RewriteRule ^(.*)$ index.php/$1 [QSA,L]
       </IfModule>

       # for Apache FCGI installations
       <IfModule !mod_php5.c>
           RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
       </IfModule>
   </IfModule>

</IfModule>



RE: redirect not working - hadeel - 12-10-2014

i have tried your code still same problem and if changed the .htaccess all pages will be not working


RE: redirect not working - Rufnex - 12-11-2014

For a redirect on your own server you dont need a url function. just write it in that way

PHP Code:
old code
redirect
(site_url('admin/dashboard'));

new 
code
redirect
('admin/dashboard'); 

In your /application/controllers you must hava a Admin.php with a dashboard method.