PHP重定向三種方法詳解

2021-09-30 12:33:29 字數 425 閱讀 9253

方法一:header("location: url")

方法二:

方法三

php的http相關函式種提供了乙個 header()函式,首先要清楚,header()函式必須放在php程式的開頭部分,而且之前不能有另外的 header() 函式或者 setcookie() 被呼叫,如果是帶有網頁輸出,本語句必須放在標記之前。

使用如下語句:

header("location: ");

只要執行這個語句就將自動把網頁重定向到

其中的 content="5;url=$url" 表示5秒後,本網頁將自動轉向 $url這個位址 。

location.href=""

PHP URL重定向的三種方法

1.使用header 函式 php的http相關函式種提供了乙個 header 函式,首先要清楚,header 函式必須放在php程式的開頭部分,而且之前不能有另外的 header 函式或者 setcookie 被呼叫,如果是帶有網頁輸出,本語句必須放在標記之前。使用如下語句 header loca...

python重定向的三種方式

使用django中的redirect方法,也是最常用的方法 from django.shortcuts import redirectreturn redirect 重定向預設都是302 臨時重定向 加上permanent就可以設定為301 永久重定向 return redirect permane...

PHP爬蟲的三種方法

定義 file get contents 函式把整個檔案讀入乙個字串中。語法 file get contents path,include path,context,start,max length 引數 描述path 必需。規定要讀取的檔案。include path 可選。如果也想在 includ...