2014-07-17 50 views
0

我用laravel 4.1.30開發了一個應用程序。在我的本地機器上應用程序工作正常。但是,當我將它部署到一個共享的cPanel託管它無法正常工作。當我登錄時,它會再次重定向回登錄頁面。我通過關閉認證過濾器來測試它,並且它工作正常。但是使用認證過濾器不起作用。Laravel session not presisting

這裏是我的route.php

<?php 

/* 
|-------------------------------------------------------------------------- 
| Application Routes 
|-------------------------------------------------------------------------- 
| 
| Here is where you can register all of the routes for an application. 
| It's a breeze. Simply tell Laravel the URIs it should respond to 
| and give it the Closure to execute when that URI is requested. 
| 
*/ 

Route::get('/',function(){ 
    return Redirect::to("/login"); 
}); 

Route::get("login", array('as' => 'login', function(){ 
    return View::make("admin.login"); 
}))->before("guest"); 

Route::post("login", "[email protected]"); 
Route::get("logout", "[email protected]"); 
Route::get("/admin", array('as' => 'admin', 'uses' => "[email protected]"))->before("auth"); 

Route::get("/admission", "[email protected]"); 
Route::get("/admission/create", "[email protected]"); 
Route::post("/admission/save", "[email protected]"); 
Route::get("/admission/edit", "[email protected]"); 

Route::get("/category", "[email protected]"); 
Route::get("/category/create", "[email protected]"); 
Route::get("/category/edit", "[email protected]"); 
Route::post("/category/save", "[email protected]"); 

Route::get("/sells/loadTable", "[email protected]"); 
Route::get("/sells/create", "[email protected]"); 
Route::post("/sells/save", "[email protected]"); 
Route::get("/sells/selection", "SellsCon[email protected]"); 
Route::get("/sells/pdf", "[email protected]"); 
Route::get("/sells/view", "[email protected]"); 
Route::get("/sells/reportForm", "[email protected]"); 
Route::post("/sells/report", "[email protected]"); 

Route::get("/product/loadTable", "[email protected]"); 
Route::get("/product/create", "[email protected]"); 
Route::get("/product/view", "[email protected]"); 
Route::post("/product/save", "[email protected]"); 
Route::get("/product/inventory", "[email protected]"); 
Route::post("/product/updateInventory", "[email protected]"); 
Route::get("/product/selection", "[email protected]"); 
Route::get("/product/history", "[email protected]"); 

Route::get("/package/loadTable", "[email protected]"); 
Route::get("/package/create", "[email protected]"); 
Route::post("/package/save", "[email protected]"); 

Route::controller('user', 'UserController'); 

Route::get("test", function(){ 
    $ym = DateTime::createFromFormat('m/d/Y h:i:s', '10/16/2003 00:00:00')->format("y-m-d h:i:s"); 
    $x = new DateTime("07/01/2014 00:00:00"); 
    $y = new DateTime("07/01/2014 23:59:59"); 
    $x = Sell::whereRaw("created_at >= ? and created_at <= ?", array($x, $y))->get(); 
    return $x; 
}); 

這是filter.php

<?php 

/* 
|-------------------------------------------------------------------------- 
| Application & Route Filters 
|-------------------------------------------------------------------------- 
| 
| Below you will find the "before" and "after" events for the application 
| which may be used to do any work before or after a request into your 
| application. Here you may also register your custom route filters. 
| 
*/ 

App::before(function($request) 
{ 
    date_default_timezone_set('Asia/Dhaka'); 

}); 


App::after(function($request, $response) 
{ 
    // 
}); 

/* 
|-------------------------------------------------------------------------- 
| Authentication Filters 
|-------------------------------------------------------------------------- 
| 
| The following filters are used to verify that the user of the current 
| session is logged into this application. The "basic" filter easily 
| integrates HTTP Basic authentication for quick, simple checking. 
| 
*/ 

Route::filter('auth', function() 
{ 
    if (Auth::guest()) { 
     return Redirect::guest('login'); 
    } 
}); 




Route::filter('auth.basic', function() 
{ 
    return Auth::basic(); 
}); 

/* 
|-------------------------------------------------------------------------- 
| Guest Filter 
|-------------------------------------------------------------------------- 
| 
| The "guest" filter is the counterpart of the authentication filters as 
| it simply checks that the current user is not logged in. A redirect 
| response will be issued if they are, which you may freely change. 
| 
*/ 

Route::filter('guest', function() 
{ 
    if (Auth::check()) return Redirect::to('/admin'); 
}); 

/* 
|-------------------------------------------------------------------------- 
| CSRF Protection Filter 
|-------------------------------------------------------------------------- 
| 
| The CSRF filter is responsible for protecting your application against 
| cross-site request forgery attacks. If this special token in a user 
| session does not match the one given in this request, we'll bail. 
| 
*/ 

Route::filter('csrf', function() 
{ 
    if (Session::token() != Input::get('_token')) 
    { 
     throw new Illuminate\Session\TokenMismatchException; 
    } 
}); 

Route::filter('super_admin', function(){ 
    if(!Auth::check() || Auth::user()->weight < 5) { 
     return array('status' => 'error', 'message' => 'You do not have right permission'); 
    } 
}); 

Route::filter('admin', function(){ 
    if(!Auth::check() || Auth::user()->weight < 4) { 
     return array('status' => 'error', 'message' => 'You do not have right permission'); 
    } 
}); 

Route::filter('normal', function(){ 
    if(!Auth::check() || Auth::user()->weight < 3) { 
     return array('status' => 'error', 'message' => 'You do not have right permission'); 
    } 
}); 

這是我session.php文件

<?php 

return array(

    /* 
    |-------------------------------------------------------------------------- 
    | Default Session Driver 
    |-------------------------------------------------------------------------- 
    | 
    | This option controls the default session "driver" that will be used on 
    | requests. By default, we will use the lightweight native driver but 
    | you may specify any of the other wonderful drivers provided here. 
    | 
    | Supported: "file", "cookie", "database", "apc", 
    |   "memcached", "redis", "array" 
    | 
    */ 

    'driver' => 'file', 

    /* 
    |-------------------------------------------------------------------------- 
    | Session Lifetime 
    |-------------------------------------------------------------------------- 
    | 
    | Here you may specify the number of minutes that you wish the session 
    | to be allowed to remain idle before it expires. If you want them 
    | to immediately expire on the browser closing, set that option. 
    | 
    */ 

    'lifetime' => 30, 

    'expire_on_close' => true, 

    /* 
    |-------------------------------------------------------------------------- 
    | Session File Location 
    |-------------------------------------------------------------------------- 
    | 
    | When using the native session driver, we need a location where session 
    | files may be stored. A default has been set for you but a different 
    | location may be specified. This is only needed for file sessions. 
    | 
    */ 

    'files' => storage_path().'/sessions', 

    /* 
    |-------------------------------------------------------------------------- 
    | Session Database Connection 
    |-------------------------------------------------------------------------- 
    | 
    | When using the "database" or "redis" session drivers, you may specify a 
    | connection that should be used to manage these sessions. This should 
    | correspond to a connection in your database configuration options. 
    | 
    */ 

    'connection' => null, 

    /* 
    |-------------------------------------------------------------------------- 
    | Session Database Table 
    |-------------------------------------------------------------------------- 
    | 
    | When using the "database" session driver, you may specify the table we 
    | should use to manage the sessions. Of course, a sensible default is 
    | provided for you; however, you are free to change this as needed. 
    | 
    */ 

    'table' => 'sessions', 

    /* 
    |-------------------------------------------------------------------------- 
    | Session Sweeping Lottery 
    |-------------------------------------------------------------------------- 
    | 
    | Some session drivers must manually sweep their storage location to get 
    | rid of old sessions from storage. Here are the chances that it will 
    | happen on a given request. By default, the odds are 2 out of 100. 
    | 
    */ 

    'lottery' => array(2, 100), 

    /* 
    |-------------------------------------------------------------------------- 
    | Session Cookie Name 
    |-------------------------------------------------------------------------- 
    | 
    | Here you may change the name of the cookie used to identify a session 
    | instance by ID. The name specified here will get used every time a 
    | new session cookie is created by the framework for every driver. 
    | 
    */ 

    'cookie' => 'chcool_session', 

    /* 
    |-------------------------------------------------------------------------- 
    | Session Cookie Path 
    |-------------------------------------------------------------------------- 
    | 
    | The session cookie path determines the path for which the cookie will 
    | be regarded as available. Typically, this will be the root path of 
    | your application but you are free to change this when necessary. 
    | 
    */ 

    'path' => '/', 

    /* 
    |-------------------------------------------------------------------------- 
    | Session Cookie Domain 
    |-------------------------------------------------------------------------- 
    | 
    | Here you may change the domain of the cookie used to identify a session 
    | in your application. This will determine which domains the cookie is 
    | available to in your application. A sensible default has been set. 
    | 
    */ 

    'domain' => null, 

    /* 
    |-------------------------------------------------------------------------- 
    | HTTPS Only Cookies 
    |-------------------------------------------------------------------------- 
    | 
    | By setting this option to true, session cookies will only be sent back 
    | to the server if the browser has a HTTPS connection. This will keep 
    | the cookie from being sent to you if it can not be done securely. 
    | 
    */ 

    'secure' => false, 

); 
+0

你修好了嗎? – 2plus

+0

還沒有。你有什麼主意嗎? – Rashad

回答

0

這可能是這樣的: 轉儲應用::環境();如果它說xvz,那麼檢查你的app/config中是否有xyz目錄。那裏的文件優先。