簡體   English   中英

將值從URL參數傳遞到Header:Location重定向

[英]Passing a Value from a URL Parameter to Header:Location redirect

這是我要實現的目標:

1.)打開http://example.org/go.php?url=http://www.example.com

2.)應該將301重定向到: http : //www.example.com

(測試)到目前為止,在out.php中,此方法有效:

<?php
    header("Location: http://www.example.com");
?>

所以我繼續將這段代碼放在go.php中:

<?php
if (!empty($_GET['url'])) {
    header("Location: " . $_GET['url']);
    exit();
} else {
    # print the whole $_GET arrays
    # just for debug !
    print_r($_GET);
    die("This field is empty.");
}
?>

它不起作用,這是我得到的:

A redirect to http://example.org/

http://example.org輸出:

只是文件夾內容

http://example.org/go.php輸出:

沒有值或參數

http://example.org/go.php?url=http://www.example.com輸出:

整個網址重定向回到此處

提示:該文件夾不包含任何其他文件

檢查$_GET array()中是否確實有東西。 具有exit();也是一種好習慣exit(); 標頭重定向后調用。

<?php
if (!empty($_GET['url'])) {
    header("Location: " . $_GET['url']);
    exit();
} else {
    # print the whole $_GET arrays
    # just for debug !
    print_r($_GET);
    die("This field is empty.");
}
?>

除了代碼之外,請嘗試弄清楚到底什么不起作用(例如,您收到錯誤消息等)-我們沒有水晶球。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM