2
A
回答
2
header("Location: http://domain.com/folder/page.html", 301);
exit();
此代碼必須是腳本的第一個輸出。生成任何輸出到客戶端後,您無法執行重定向。一旦將重定向發送到客戶端,您可以退出腳本,因爲用戶不會看到生成的任何其他輸出。
10
如果你的開發MVC你應該有一個輸入級和一個輸出級(I/O),你應該創建一個名爲函數的輸出類中的重定向,並從自己的基本網址建立新的網址,像這樣:
public function redirect($controller,$method = "index",$args = array())
{
global $core; /* Guess Obviously */
$location = $core->config->base_url . "/" . $controller . "/" . $method . "/" . implode("/",$args);
/*
* Use @header to redirect the page:
*/
header("Location: " . $location);
exit;
}
這種方式在你的控制器中,你可以簡單地使用輸入類來做你的重定向。
class MyController extends BaseController
{
public function login()
{
if($this->library->session->exists("user_logged_in") === false)
{
$this->library->output->redirect("MyController","login",array("from:login"));
}
}
/*
..More Here
*/
}
相關問題
- 1. PHP MVC的.htaccess重定向
- 2. 301在mvc中重定向
- 3. 在PHP中重定向
- 4. htaccess在php中重定向
- 5. htaccess PHP MVC重定向到https
- 6. PHP,MVC,404 - 如何重定向到404?
- 7. .htaccess奇怪的重定向PHP MVC
- 8. Spring MVC:在@ResponseBody中重定向
- 9. 避免在asp.net中重定向mvc
- 10. 在MVC上的Application_BeginRequest中重定向
- 11. 重定向仍然在Spring MVC中
- 12. PHP - 重定向
- 13. PHP重定向
- 14. 重定向PHP
- 15. php重定向
- 16. 如何更改303重定向到301在PHP中重定向
- 17. 重定向在PHP中不包括重定向主頁
- 18. 頁面重定向在PHP
- 19. 重定向通過在PHP
- 20. 頭重定向不在PHP
- 21. ASP淨MVC域重定向
- 22. Spring MVC - 重定向頁面
- 23. URL重定向issue.in asp.net mvc
- 24. 從MVC重定向aspx
- 25. asp.net mvc ajax.BeginForm重定向
- 26. MVC重定向問題
- 27. c#MVC 5 RouteConfig重定向
- 28. IIS - ASP.NET MVC重定向
- 29. Asp.net Mvc重定向Url
- 30. Asp.net mvc 301重定向
http://php.net/manual/en/function.header.php – stecb 2011-02-12 17:57:22
你的問題與MVC無關。 – mario 2011-02-12 18:07:17
馬里奧,你不明白他的問題。請看下面的答案。 – Nathan 2012-02-18 04:06:46