php 頁面跳轉實現程式碼

來源:互聯網
上載者:User

最簡單的就是利用php header實現

代碼是:

 代碼如下 複製代碼

<?php
header("Location:http://www.111cn.net/");
?>

或者:

<? header("location:index123.php"); ?>

通過get或post擷取值再跳轉

有時候可以看到http://www.xxx.com/url.php?url=http://www.baidu.com,然後就跳轉到百度。
如何用php實現這個url跳轉呢?
只用簡單的幾行代碼,就可以實現。

 代碼如下 複製代碼

<?php
$url=$_GET["url"];
header("Location:".$url);
?>

PHP 301轉向實現代碼

 代碼如下 複製代碼

<?php
$url=""];
header("HTTP/1.1 301 Moved Permanently");
header ("Location:$url");
?>

在ff看到狀態碼

容易吧.要測試就用curl這個小軟體來檢查.
#curl -I
HTTP/1.0 301 Moved Permanently
Date: Tue, 06 May 2008 06:27:39 GMT
Server: apache
Location:
如見到上面的HTTP/1.0 301 Moved Permanently

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.